Object Types in Python 2.6 and 3.0
Code
def inspect(x):
print(repr(x))
print("type = %s" % type(x))
print("class = %s" % x.__class__)
print("")
class X:
pass
class Y(object):
pass
inspect(1)
inspect('Hej!')
inspect(X())
inspect(Y())
Python 2.6
1
type = <type 'int'>
class = <type 'int'>
'Hej!'
type = <type 'str'>
class = <type 'str'>
<__main__.X instance at 0x851c0>
type = <type 'instance'>
class = __main__.X
<__main__.Y object at 0x82c50>
type = <class '__main__.Y'>
class = <class '__main__.Y'>
|
Python 3.0
1
type = <class 'int'>
class = <class 'int'>
'Hej!'
type = <class 'str'>
class = <class 'str'>
<__main__.X object at 0xffa10>
type = <class '__main__.X'>
class = <class '__main__.X'>
<__main__.Y object at 0xffa10>
type = <class '__main__.Y'>
class = <class '__main__.Y'>
|