随笔分类 -  Python

上一页 1 ··· 5 6 7 8 9 10 11 下一页
摘要:# 回文数 121 是; 123 不是 #定义一个函数 判断是否是回文数 def get_Hui(num): #将整数num转字符串 str_num = str(num) str_num_change = str_num[::-1] num2 = int(str_num_change) #判断整数n 阅读全文
posted @ 2023-06-29 21:13 胖豆芽 阅读(56) 评论(0) 推荐(0)
摘要:https://leetcode.cn/problemset/all/ 第7题 整数取反在 Python 中,切片(slicing)是一种从序列(如字符串、列表、元组等)中获取子序列的方法,不能对整数做切片,需要先转序列为整数。切片操作使用方括号 `[]` 来实现,可以包含开始索引、结束索引和步长。 阅读全文
posted @ 2023-06-29 20:50 胖豆芽 阅读(61) 评论(0) 推荐(0)
摘要:调用函数# 整数转16进制 没有.hex 而是直接 hex(参数) n1 = 255 n2 = 1000 print(hex(n1)) print(hex(n2)) 定义函数# 定义函数 获得正数 def my_abs(x): if x>=0: return x; else: return -x; 阅读全文
posted @ 2023-06-29 20:29 胖豆芽 阅读(14) 评论(0) 推荐(0)
摘要:# 字典 zd={'name': 'fqs', 'age': 36, 'class':1, 'w': 'ww'} print(zd['name']) # 更改字典内的值 zd['name']='douDou' print(zd) # 判断字典内是否存在某个值 # 第一种 写值 print('fqs' 阅读全文
posted @ 2023-06-29 19:14 胖豆芽 阅读(7) 评论(0) 推荐(0)
摘要:# 判断 print("请输入你的年龄") age = int(input()) if age >=18: print(f'你的年龄是:{age},成年了') else: print("小于18未成年") # 判断print("请输入你的年龄")age = int(input())if age >= 阅读全文
posted @ 2023-06-29 17:51 胖豆芽 阅读(30) 评论(0) 推荐(0)
摘要:# list列表 classmate = ["lily", "jjj", "hhh"] # 打印列表的长度 print(len(classmate)) # 打印下标为0的 print(classmate[0]) # 打印下标为-1的元素 倒数第一个元素 print(classmate[-1]) # 阅读全文
posted @ 2023-06-29 16:52 胖豆芽 阅读(10) 评论(0) 推荐(0)
摘要:print('I\'m ok') 第二种 print(r"I'm ok") 打印 多行 print('''第一行 第二行 第三行''') D:\pythonProject\venv\Scripts\python.exe D:/pythonProject/main.py第一行第二行第三行 运算符 # 阅读全文
posted @ 2023-06-29 15:13 胖豆芽 阅读(104) 评论(0) 推荐(0)
摘要:''' 字符串 split后成为列表 对列表list做倒叙的[::-1] 如果列表仅包含一个"内容",需要指定下标[0][::-1] ''' #定义方法获取 列表 指定下标的 list_name=["a","b","c"] list_name2=["abc"] list_name3="abcd,ef 阅读全文
posted @ 2023-04-11 22:32 胖豆芽 阅读(81) 评论(0) 推荐(0)
摘要:数据容器 1. list 列表[] ''' 字符串 split后成为列表 对列表list做倒叙的[::-1] ''' #定义方法获取 列表 指定下标的 list_name=[0,1,2,3,4,5] list_name2=[-4,-3,-2,-1] list_name3="abcd,efg" def 阅读全文
posted @ 2023-04-10 21:39 胖豆芽 阅读(29) 评论(0) 推荐(0)
摘要:''' 元组学生 ("fqs",11,["football","music"]) 1.查询年龄所在的下标 2.查询学生姓名 3.删除学生爱好中的football 4.增加爱好 coding ''' #定义方法 def get_student(): tuple_student=("fqs",11,[" 阅读全文
posted @ 2023-04-07 23:02 胖豆芽 阅读(75) 评论(0) 推荐(0)
摘要:''' 元组 ''' #定义方法 def get_num(): # 1.定义一个元祖 tuple_one=("fqs",18,"f",18,18,18,18) print(f"tuple_one元祖:{tuple_one}") # 2.单个元祖内元素要注意 ("fqs") 类型是str 字符串;(" 阅读全文
posted @ 2023-04-07 22:51 胖豆芽 阅读(56) 评论(0) 推荐(0)
摘要:''' 求列表中的偶数,并放到新的列表中 ''' #定义方法 def get_ou(): list_num=[1,2,3,4,5] list_ou=[] index=0 while index<len(list_num): if list_num[index] % 2 == 0: print(f"偶 阅读全文
posted @ 2023-04-07 22:06 胖豆芽 阅读(247) 评论(0) 推荐(0)
摘要:''' while循环打印整个数组 ''' name_list=["fqs","doudou","oldwang"] #下标从0开始 index=0 #求数组的长度 len_list=len(name_list) while index<len_list: print(f"第{index+1}个元素 阅读全文
posted @ 2023-04-07 21:14 胖豆芽 阅读(95) 评论(0) 推荐(0)
摘要:增1.列表.append(元素) 向列表追加元素2.列表.extend(元素) 将数据容器的内容一次取出,追加到元素的尾部3.列表.insert(下标,元素) 在指定下标处,插入指定的元素删4.del列表[下标] 删除列表指定下标元素5.列表.pop(下标) 删除列表指定下标元素6.列表.remov 阅读全文
posted @ 2023-04-06 22:43 胖豆芽 阅读(27) 评论(0) 推荐(0)
摘要:''' ATM 当前的剩余金额是个不断变化的过程 需要在存款 取款函数中声明为全局变量自己写的 ''' money_now=5000 name="fqs" def look_money_now(): print(f"{name}您的余额是{money_now}") def money_up(): m 阅读全文
posted @ 2023-04-05 15:23 胖豆芽 阅读(49) 评论(0) 推荐(0)
摘要:''' 函数嵌套 更改全局变量使用 声称全局变量 global ''' number = 100 def b (): print(f"方法b中number:{number}") def a (): #注意 只有调用函数数 global 才能生效 global number number = 200 阅读全文
posted @ 2023-04-05 14:38 胖豆芽 阅读(65) 评论(0) 推荐(0)
摘要:''' 函数返回值 ''' def add(a,b): #结果result=a+b result=a+b #返回 结果值 return result r=add(1,2) print(r) 阅读全文
posted @ 2023-04-04 22:43 胖豆芽 阅读(25) 评论(0) 推荐(0)
摘要:''' 函数传参 ''' def is_ok(persion,du): if du>37.5 : print(f"{persion},你需要隔离") else: print(f"{persion},温度正常,请进") is_ok("fqs",39) is_ok("doudou",37) 阅读全文
posted @ 2023-04-04 22:33 胖豆芽 阅读(19) 评论(0) 推荐(0)
摘要:''' 函数的意义 ''' #求每个字符串的长度 str1="fqs123" str2="doudou" count=0 for i in str1: count+=1 print(str(count)) count=0 for i in str2: count+=1 print(str(count 阅读全文
posted @ 2023-04-04 21:53 胖豆芽 阅读(21) 评论(0) 推荐(0)
摘要:''' continue break 公司有1万元 有20个员工来领工资 每人领取1千元 随机数绩效1到10 如果低于5 不发工资 下一位 如果领取完了 结束发工资 ''' #工资总和是1万元 每个人1千 #20个人的绩效 import random he=10000 while he>0 : ji 阅读全文
posted @ 2023-04-04 21:04 胖豆芽 阅读(34) 评论(0) 推荐(0)

上一页 1 ··· 5 6 7 8 9 10 11 下一页