4

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?

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.