"""
1.递归访问目录: 且目录中嵌套目录,有层次的列出给定目录中所有的文件和文件夹
# 切换目录: os.chdir(path)
# 列出当前目录中所有的文件和文件夹 os.listdir(path), path: 绝对路径
# 判断是否是文件: os.path.isfile(path)
# 判断是否是目录: os.path.isdir(path)
# 拼接路径: os.path.join(path1, path2, path3....)
2.定义一个嵌套函数,
外层函数打印this is outing function
内层函数功能:打印This is inner function
3.定义一个递归函数:打印斐波那契数列
F[n]=F[n-1]+F[n-2](n>=2,F[0]=0,F[1]=1)
4.对列表进行排序: list_data = ["grape", "peach", "berry", "pineapple", "apple", "strayberry", "watermelon"]
排序规则:按照最后一个字符进行排序,如果最后一个字符相等,按照第一个字符排序
5.利用map函数: 计算三个列表,相同位置元素之和
list1 = [1, 2, 3]
list2 = [4, 5, 6]
list3 = [7, 8, 9]
6.利用filter函数过滤列表中所有带a的字符串
list_data = ["grape", "what", "which", "you", "friend", "am"]
7.利用reduce计算1 + 2 + 3...+ 100之和
"""
import os
os.chdir("F:\py progect")
print(os.listdir())
print(os.path.isdir("F:\py progect"))
print(os.path.isfile("F:\py progect\1"))
print(os.path.split("D:\\test\\test2"))
def outer():
print("this is outing function")
def inner():
print("This is inner function")
return inner()
print(outer())
def print_feibo(n):
if n <=1:
return n
else:
return (print_feibo(n-1)+print_feibo(n-2))
"""
num = input("请输入要打印的项数")
num= int(num)
if num < 0:
print("请输入大于0的数")
else:
for i in range(num):
print(print_feibo(i),end=" ")
"""
list_data = ["grape", "peach", "berry", "pineapple", "apple", "strayberry", "watermelon"]
list_data.sort(key= lambda x: (x[-1], x[0]))
print(list_data)
list1 = [1, 2, 3]
list2 = [4, 5, 6]
list3 = [7, 8, 9]
map_obj = map(lambda x, y, z : x+y+z, list1, list2, list3)
print(list(map_obj))
list_data = ["grape", "what", "which", "you", "friend", "am"]
from functools import reduce
data = reduce(lambda x, y: x+y, list(range(1, 101)))
print(data)