# python中的if常见写法 ifstr == "file": if [boolean] isFalse: ifnot [boolean]: if [boolean]: if projection isnotNone: if x < y < z:
for
1 2 3 4 5 6 7 8 9 10 11
# 遍历字符串中每个字符 for x in [string]: # 从0开始循环到[number]结束的数字序列 for item inrange([number]): # 从[number1]开始循环到[number2]结束的数字序列 for item inrange([number1],[number2]): # 从[number1]开始,到[number2]结束(不含第二个[number2]本身),步长以step值为准 for item inrange([number1],[number2],[step]):
defdelete_files_and_folders(folder): """ 清空文件夹 :param folder: 文件夹路径 :return: """ for root, dirs, files in os.walk(folder, topdown=False): for name in files: file_path = os.path.join(root, name) os.remove(file_path) print(f"文件 {file_path} 已被删除") for name in dirs: folder_path = os.path.join(root, name) shutil.rmtree(folder_path) print(f"文件夹 {folder_path} 及其内容已被删除")