![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Python杂碎知识点
python的一些杂碎知识
定品寻良骥,中正探人杰
这个作者很懒,什么都没留下…
展开
-
python复制文件操作
import shutilshutil.copyfile("1.txt","2.txt")#第一个参数为被复制的文件路径#第二个为复制后另存为的文件路径原创 2022-05-05 22:13:58 · 360 阅读 · 0 评论 -
python输出换行
转义符号:\nstr1 = "python"str2 = "C++"print(str1)print(str2)显示pythonC++加入\n后str1 = "python"str2 = "C++"print(str1 + "\n")print(str2)显示pythonC++原创 2022-04-24 23:09:14 · 2239 阅读 · 0 评论 -
python中浮点数取整
1.向下取整采用int强转即为向下取整b = int(7.2) # 7d = int(5.9) # 52.向上取整math中的ceil函数import mathprint(math.ceil(4.1)) #5print(math.ceil(4.9)) #53.四舍五入round()函数print(round(4.1)) #4print(round(4.9)) #5原创 2022-04-24 23:01:03 · 913 阅读 · 0 评论 -
python中列表随机出指定大小的子列表
import randomlist1 = [1,3,4,2,5]list2 = random.sample(list1,3)#3为子列表长度,大于list1长度报错,0为空列表print(list2)显示[5,1,4]另外,随机返回一个值。函数为:a = random.choice(list1)也可以自己写随机数去索引(效率低)...原创 2022-04-24 22:53:33 · 1095 阅读 · 0 评论