03 2022 档案

摘要:# 如果文件有很多行 with open('eg.txt',mode='r',encoding="utf-8") as file_object: for line in file_object: pass # 如果文件只有一行import osfile_size = os.path.getsize( 阅读全文
posted @ 2022-03-29 20:26 美丽小鱼 阅读(307) 评论(0) 推荐(0)
摘要:max_page_num, remainder = divmod(8, 3)if remainder: max_page_num += 1print(max_page_num,remainder) 阅读全文
posted @ 2022-03-28 15:58 美丽小鱼 阅读(46) 评论(0) 推荐(0)
摘要:import hashlibdef md5(origin, salt="ghjhfkasn,ijkll"): hash_object = hashlib.md5(salt.encode('utf-8')) hash_object.update(origin.encode('utf-8')) resu 阅读全文
posted @ 2022-03-26 12:52 美丽小鱼 阅读(20) 评论(0) 推荐(0)
摘要:data_list = [ '1-11 ceshi.mp4']result = sorted(data_list, key=lambda x: int(x.split(' ')[0].split("-")[-1]) )print(result) 阅读全文
posted @ 2022-03-24 19:32 美丽小鱼 阅读(29) 评论(0) 推荐(0)
摘要:import randomdef gen_random_num(max_count): counter = 0 while counter < max_count: yield random.randint(1000, 9999) counter += 1data_list = gen_random 阅读全文
posted @ 2022-03-24 16:50 美丽小鱼 阅读(33) 评论(0) 推荐(0)
摘要:import functoolsprint("第一回合".center(30,"*"))def func(): print("我是func函数") value = (11,22,33,44) return valuedef outer(origin): def inner(): print("bef 阅读全文
posted @ 2022-03-23 22:04 美丽小鱼 阅读(88) 评论(0) 推荐(0)
摘要:info = { "1":[11,22,33], "2":{"k1":123,"k2":456,"k3":999},}index = input("请输入编号:")value = info[index]if type(value) == list: for i in value: print(i)i 阅读全文
posted @ 2022-03-23 15:41 美丽小鱼 阅读(16) 评论(0) 推荐(0)
摘要:如果定义一个函数,return返回多个值,则返回形式为元祖,即用括号括起来 阅读全文
posted @ 2022-03-22 21:29 美丽小鱼 阅读(240) 评论(0) 推荐(0)
摘要:文件路径处理: base_dir = os.path.dirname(os.path.abspath(__file__))download_folder = os.path.join(base_dir, 'files', 'package')if not os.path.exists(downloa 阅读全文
posted @ 2022-03-20 17:47 美丽小鱼 阅读(46) 评论(0) 推荐(0)
摘要:原来的实现方法: data_list = [11, 22, 33, 44, 55]for index in range(len(data_list)): print(index+1, data_list[index]) 新的实现方法: data_list = [11, 22, 33, 44, 55] 阅读全文
posted @ 2022-03-20 17:42 美丽小鱼 阅读(31) 评论(0) 推荐(0)
摘要:Python 字典 in 操作符用于判断键是否存在于字典中,如果键在字典 dict 里返回 true,否则返回 false。 而 not in 操作符刚好相反,如果键在字典 dict 里返回 false,否则返回 true。 in 操作符语法: key in dict 实例 thisdict = { 阅读全文
posted @ 2022-03-19 15:13 美丽小鱼 阅读(472) 评论(0) 推荐(0)
摘要:在a模式下,调用write在文件中写入内容时候,永远只能将内容写入到尾部,不会写入光标的位置。 阅读全文
posted @ 2022-03-19 13:55 美丽小鱼 阅读(19) 评论(0) 推荐(0)
摘要:1、进制之间转换 - 十进制转其他:bin、oct、hex- 其他进制转十进制:int("其他进制",base=2或8或16) 阅读全文
posted @ 2022-03-17 17:45 美丽小鱼 阅读(35) 评论(0) 推荐(0)
摘要:1、数据类型中哪些是可变的类型? listsetdict 2、数据类型中哪些是可哈希的类型? intboolfloatstrtuple 3、数据类型(容器)中哪些是有序的? listtupledict(py3.6之后) 独有方法: 4、str stripsplitjoinstartswithends 阅读全文
posted @ 2022-03-17 17:44 美丽小鱼 阅读(45) 评论(0) 推荐(0)
摘要:首字母大写:capitalize() 全部大写:upper() 阅读全文
posted @ 2022-03-17 09:39 美丽小鱼 阅读(80) 评论(0) 推荐(0)
摘要:from colorama import initimport time# 设置init状态解决cmd不显示颜色问题init(autoreset=True)while True: print("="*50) text = input('请输入需要检测的文本:') lst = ['关键字1','关键字 阅读全文
posted @ 2022-03-16 16:30 美丽小鱼 阅读(179) 评论(0) 推荐(0)
摘要:v1 = [] or "lili" #[]是空值为false,or则需要看后面的值,有一个true就是true,因此结果为lili v2 = [11,22] and (1,2,) #and前面是true时,主要看后面的,有一个False就是False,因此结果为(1,2,) 阅读全文
posted @ 2022-03-16 16:25 美丽小鱼 阅读(24) 评论(0) 推荐(0)
摘要:# 错误方式, 有坑,结果不是你想要的。user_list = ["刘的话", "范德彪", "刘华强", '刘尼古拉斯赵四', "宋小宝", "刘能"]for item in user_list: if item.startswith("刘"): user_list.remove(item) pr 阅读全文
posted @ 2022-03-16 09:59 美丽小鱼 阅读(14) 评论(0) 推荐(0)
摘要:int,整数类型(整形) bool,布尔类型 str,字符串类型 list,列表类型 tuple,元组类型 dict,字典类型 set,集合类型 float,浮点类型(浮点型) 阅读全文
posted @ 2022-03-16 09:45 美丽小鱼 阅读(85) 评论(0) 推荐(0)
摘要:1、清空原列表 user_list = ["王宝强","陈羽凡","lili","贾乃亮","yaya"]user_list.clear()print(user_list) # [] 2、根据索引踢出某个元素pop(根据索引位置删除) user_list = ["王宝强","陈羽凡","lili", 阅读全文
posted @ 2022-03-16 09:38 美丽小鱼 阅读(329) 评论(0) 推荐(0)
摘要:不可变类型:字符串、布尔、整型(已最小,内部数据无法进行修改) 可变类型:列表(内部数据元素可以修改) 元祖本身不可以改变,但是如果嵌套列表,其列表可以改变。举例说明: 记住一句话:《"我儿子永远不能换成是别人,但我儿子可以长大"》 data = ("123",666,[11,22,33], ("l 阅读全文
posted @ 2022-03-16 09:23 美丽小鱼 阅读(50) 评论(0) 推荐(0)