09-15-周一_16-08-20
This commit is contained in:
@@ -473,4 +473,15 @@ print(isinstance([1,2,3], Iterable)) # True
|
||||
print(issubclass(list,Iterable)) # True
|
||||
|
||||
# 由上面的例子可得,这些可迭代的数据类型,list str tuple dict等 都是 Iterable的子类。
|
||||
```
|
||||
```
|
||||
|
||||
这种继承关系形成了Python对象模型的闭环:object是所有类的基类,type是所有类型的基类,而type本身又是object的子类。
|
||||
|
||||
```python
|
||||
print(isinstance(object, type))
|
||||
print(issubclass(type, object))
|
||||
|
||||
# object是type的实例(因为type创建了object类)
|
||||
# type是object的子类(因为所有类都继承自object,包括type本身)。
|
||||
```
|
||||
|
||||
|
Reference in New Issue
Block a user