Python有一個重要的概念,一切皆對象。
一切都可以賦值給變量:
內置類型賦值:
1 >>> a=1 2 >>> b='abc' 3 >>> type(a) 4 <class 'int'> 5 >>> type(b) 6 <class 'str'>
將類類型賦值給變量:
1 >>> a=int 2 >>> a('123') 3 123 4 >>> type(a) 5 <class 'type'>
將函數賦值給變量:
1 >>> def my_func(x): 2 ... print(x) 3 ... 4 >>> a=my_func 5 >>> a(8) 6 8
將自定義類賦值給:
1 >>> class Person: 2 ... pass 3 ... 4 >>> a=Person 5 >>> p = a() 6 >>> type(p) 7 <class '__main__.Person'>
。。。