2
class Car():
def __init__(self,input):
self.carName = input
def showName(self):
print self.carName
a = Car("bmw")
print type(a)
print a
這將返回我我無法理解類<classname>(unicode):在Python中?
<type 'instance'>
<__main__.Car instance at 0x7f188f38de60>
而
class Car(unicode):
def __init__(self,input):
self.carName = input
def showName(self):
print self.carName
a = Car("bmw")
print type(a)
print a
<class '__main__.Car'>
bmw
據我瞭解,打印觸發的對象。 str()方法但unicode在這裏的意義是什麼?
我想試驗,是'__str__'方法,爲Unicode類定義?我很抱歉,但我無法找到正確的文檔。 – sharky 2013-04-10 05:37:14
@sharky:當然'unicode'有'__str__'(和其他許多方法)。試試'dir(u'')'。 – NPE 2013-04-10 05:39:32
謝謝,通過這樣做我也遇到了'__dict__'方法,+1 – sharky 2013-04-10 05:50:50