When trying the following script in Python 2,
a = 200
print type(a)
its output is
<type 'int'>
and in Python 3, the script
a = 200
print (type(a))
its output is,
<class 'int'>
What may be the reason for that?
In the days of yore, built-in types such as int
and dict
and list
were very different from types built with class
. You could not subclass built-in types for example.
Gradually, in successive Python 2.x releases, the differences between class
types and builtin types have eroded; the introduction of new-style classes (inheriting from object
) in Python 2.2 was one such (major) step. See Unifying types and classes in Python 2.2.
Removing the use of type
in built-in type representations is just the last step in that process. There was no reason anymore to use the name type
anymore.
In other words, between Python 2.7 and 3.x this is a cosmetic change, nothing more.
type
isn't behaving any differently. They just changed things so all classes show up as <class ...>
instead of <type ...>
, regardless of whether the class is a built-in type like int
or a class created with the class
statement. It's one of the final steps of the elimination of the class/type distinction, a process that began back in 2.2.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With