0

From Python2:

>>> class A: pass
... 
>>> a = A()
>>> type(a)
<type 'instance'>

from Python3:

>>> class A: pass
... 
>>> a = A()
>>> type(a)
<class '__main__.A'>

First of all, I have noticed that in python2 it returns<type....> while in python3 <class....> is it only a different way of display or is there a more deep meaning?

Second, does type function in python2 always return instance for object created by user-defined class?

zer0uno
  • 7,521
  • 13
  • 57
  • 86
  • `class A(object): pass`, `type(A)` -> ``, in both Python 2 and 3. – Martijn Pieters Jun 17 '14 at 15:13
  • so what about `` and ``? If I do `type([])` I get `` in python2 while in python3 ``, is there a deeper meaning? – zer0uno Jun 17 '14 at 15:18
  • No; Python 2 separated types and custom classes, but they were [unified in 2.2](https://www.python.org/download/releases/2.2/descrintro/), with further refinements to the [new-style class model in 2.3](https://www.python.org/download/releases/2.3/mro/). Python 3 ditched the old-style classes altogether and tweaked the naming; `` in Python 2 is exactly the same thing as `` in Python 3. – Martijn Pieters Jun 17 '14 at 15:24

0 Answers0