因为python 不需要预先声明,需要用的时候自己创建对象,然后同一个对象的值也可以由不同的数据类型来赋。
>>> temp = abc()
>>> temp.a
Traceback (most recent call last):
File "<pyshell#45>", line 1, in <module>
temp.a
AttributeError: abc instance has no attribute 'a'
>>> temp.a = 1
>>> temp.a
1
>>> temp2 = abc()
>>> temp2.a
Traceback (most recent call last):
File "<pyshell#49>", line 1, in <module>
temp2.a
AttributeError: abc instance has no attribute 'a'
>>> temp.a
1
>>> tList = [1,2]
>>> tList
[1, 2]
>>> tList[2] = 3
Traceback (most recent call last):
File "<pyshell#53>", line 1, in <module>
tList[2] = 3
IndexError: list assignment index out of range
>>> tList.append(3)
>>> tList
[1, 2, 3]
>>> dir(temp)
['__doc__', '__module__', 'a']
>>> dir(temp2)
['__doc__', '__module__']
temp从abc类实例化后,a成员增加到temp对象中。