python 2023
一切对象都是type类创建出来的
一切对象的基类都是object
对象的特点:
1、唯一标识 id()
2、类型 type()
3、值
None类型全局只有一个
a=10 print(id(a)) print(type(a)) print(type(int)) print(a) def fun(): print(111) print(id(fun)) print(type(fun)) print(fun) class Student: def __init__(self): pass print(id(Student)) print(type(Student)) print(Student) #### 140718017992000 <class 'int'> <class 'type'> 10 2662809125344 <class 'function'> <function fun at 0x0000026BFBCAC1E0> 2662843633544 <class 'type'> <class '__main__.Student'>
def my_wrapper(funobj): def wrapper(): print('这是一个装饰器') funobj() return wrapper @my_wrapper def fun(): print('这是一个函数') #my_wrapper(fun)() fun() print(type(fun)) print(type(object)) ##<class 'type'> a=12 print(type.__bases__) ##__bases__ 看继承关系 object print(type.__bases__) ## () class Student: def __init__(self,arr): self.arr=arr def __getitem__(self, item):##可以让当前类具有序列取值 print(item) return self.arr[item] stu=Student(['aa','bb','cc']) for s in stu: print(s)