Python随笔记录之一
import os import random from copy import deepcopy ''' 读取特定目录下所有的文件夹, 和文件名 ''' def eachDir(path): for fileDirPath,dirName,fileName in os.walk(path): print('当前文件夹路径:',fileDirPath) print('当前文件夹目录下包含的文件夹:',dirName) print('当前文件夹目录下包含的文件名',fileName) ''' 深拷贝 ''' def dpCopy(arr): copyArr = deepcopy(arr) return copyArr ''' 随机取字符串 ''' def choiceStr(): for i in range(10): group = random.choice(["白月初", "东方月初", "苏苏", "红红", "王富贵", "清瞳"]) print("第", i+1,"周", group, "打扫教室...") ''' 反向切片 ''' def desc(arr): return arr[::-1]