class Asset(object):
def __init__(self,id,price):
self.__id=id
self.__price=price
def getID(self):
return(self.__id)
def setID(self,idValue):
if type(idValue)!=str:
return("Attention!! The type of id must be string!")
self.__id=idValue
asset7=asset('007',27)
Traceback (most recent call last):
File "<ipython-input-8-e24635745b8c>", line 1, in <module>
asset7=asset('007',27)
NameError: name 'asset' is not defined
asset7=Asset('007',27)
print(asset7.getID)
<bound method Asset.getID of <__main__.Asset object at 0x00000238A4787320>>
asset7.getID
Out[11]: <bound method Asset.getID of <__main__.Asset object at 0x00000238A4787320>>
是因为调用对象函数时候没加()
asset7.getID()
Out[12]: '007'