擅长:python、mysql、java
<p>使用</p>
<pre><code>type('object')
</code></pre>
<p>请参见下面使用Python3.2的示例</p>
<pre><code>class Person(object):
def opinion(self):
print(type(self))
print ("Time for a cup of tea")
class Programmer(Person):
def opinion(self):
super(Programmer, self).opinion()
print ("There is no spoon")
if '__name__' == '__main__':
programmer = Programmer()
programmer.opinion()
p = Person()
p.opinion()
print('\n')
pg = Programmer()
pg.opinion()
</code></pre>
<p><strong>结果</strong></p>
<pre><code><class '__main__.Person'>
Time for a cup of tea
<class '__main__.Programmer'>
Time for a cup of tea
There is no spoon
</code></pre>
<p>可以看出第一个结果是由“Person”类调用的。你知道吗</p>