# 闭包 # def hello(): # username='刘阳' # def world(): # return username # return world # def hello(username): # def world(status): # return username+status # return world # world = hello() # print(world()) # from functools import reduce # sorted # lists = [2,5,2,4,7] # print(sorted(lists,reverse=True)) # filter # def get_data(x): # return x%2==0 # print(filter(get_data(range(1,101)))) # reduce 累加累乘 # def get_data(x,y): # return x+y # # 过程 # # x=1 y=2 # # x=2 y=3 # # x=6 y=4 # # print(reduce(get_data,(range(1,101)))) # map 列表输入输出1 # def get_data(x): # return x**3 # # print(list(map(get_data,[1,2,3]))) # reversed 倒序 # lists=[1,3,2,5,2] # print(list(reversed(lists))) # max min 最值 # 匿名函数 一次性调用 # get_data = lambda x:x**3 # print(get_data(3)) # print(list(map(get_data,[1,2,3]))) # get_data = lambda x,y:x+y # print(reduce(get_data,(range(1,101)))) # 类和实例 # class Student(object): # # 类属性 # province = '广东' # def __init__(self,name): # # 实例属性 # self.name = name # # 实例方法 # def say(self): # print('{}说我今天要跑步'.format(self.name)) # # 类方法 # @classmethod # def hello(cls): # print('hello world') # # 静态方法 # @staticmethod # def world(): # print('你好') # 类的实例化 # stu1 = Student('张三') # stu2 = Student('李四') # print(stu1.name,stu1.province) # print(stu2.name,stu2.province) # print(Student.province) # print(stu1.say()) # Student.hello() # Student.world() # stu1.hello() # stu1.world()
TJ20240606
于 2024-06-11 14:52:09 首次发布