
Python知识点
爬虫选手_不懂就问
这个作者很懒,什么都没留下…
展开
-
OS模块的使用
【代码】OS模块的使用。原创 2023-07-24 16:20:42 · 254 阅读 · 0 评论 -
Python——with open()的用法
1. 用途:是python用来打开本地文件的,他会在使用完毕后,自动关闭文件,相对open()省去了写close()的麻烦2. 用法:with open(file="你要打开的路径名(或保存内容的地址)",mode="r/w/a",encoding="utf-8") as f: data=f1.read/write() print(data)如果没有指定的路径,会自动新建文件,无需先去新建。2.1 关于mode的三种常用模式:r:只读 用read()w: 只写 用原创 2022-04-23 11:21:21 · 89507 阅读 · 2 评论 -
Python常用的内置函数总结
1.abs()函数:取绝对值print(abs(-10))>>>102.divmod()函数:同时取商和余数 🌟🌟print(divmod(7,2))>>>(3, 1)3.sum()函数:求和计算li=[1,2,3]print(sum(li))>>>64.round()函数:四舍五入print(round(5.1))print(round(5.5))>>>5>>原创 2022-04-08 20:07:21 · 6745 阅读 · 0 评论 -
Python排列函数和组合函数
排序函数:permutations()缺点:不能按照顺序输出下一个更大的排列from itertools import *s=['a','b','c']for i in permutations(s,2): #任取2个元素输出 a=i[0]+i[1] print(a)'''输出结果abacbabccacb'''s1=['1','2','3']for ii in permutations(s1): #全排列 a=''.join(ii) #将所有元素拼原创 2022-03-01 16:09:03 · 3776 阅读 · 0 评论 -
Python——Sort()与Sorted()的区别
sort():是在原位重新排序的,是改变原来列表的。a=[1,3,5,7,2]print(sorted(a))#1,2,3,5,7a.sort()print(a)#1,2,3,5,7而sorted():是产生一个新列表a='asdfcx'print(sorted(a))#这样就错误了:a.sort()#因为sort是应用在list上的,而a不是list...原创 2022-03-01 14:59:54 · 250 阅读 · 0 评论