摘要:
通过递归遍历所有的目录+子目录(这个问题我经常会搞不明白,希望大家能用的清楚) 1、直接显示所有文件 def showAllFiles(path): list_all =os.listdir(path) for one in list_all: one_path =os.path.join(path 阅读全文
摘要:
借用python自带的函数sorted()配合[::-1] def func6(data,n): new =sorted(data)[::-1] #通过系统函数sorted()排序,在进行取反 print(new[:n]) #以列表形式 for i in new[:n]: #逐个遍历 print(i 阅读全文
摘要:
1、传统python写法 --for 循环 def func3(maxdata): result =0 for i in range(maxdata+1): result += i print(result) 2、列表推导式写法(比较pythonic) def func4(maxdata): pri 阅读全文