1.什么是反射?
根据字符串类型的变量名来获取变量的值:
2.应用场景:
input,用户输入的字符串为变量名,则打印变量的值
文件,文件读取出来的字符串转变为变量名
网络,将网络传输的字符串转变为变量名
3反射中的变量:静态属性,类方法,静态方法
class Foo: School = 'oldboy' Country = 'China' Language = 'Chinese' @classmethod def class_1(cls): print(cls.School) @staticmethod def static_1(): print('4564') def name(self): print(451) oa = input('>>>') print(getattr(Foo,oa))