Sarravanabavan Durairaj
PRO
2 weeks ago
Sarravanabavancountry asked

Is 'int' a class or an object?

Sudip Bhandari
Expert
2 weeks ago

That's a great question!

In Python, int is actually a class, and any number you create (like 1) is an object of that class.

For example, when you write:

number = 1

Here, number is an object of the int class. You can check this using the type() function:

print(type(number))  # Output: 

This shows that int is a class, and every integer you create is an object (or instance) of that class.

Hope this helps!

Python
This question was asked as part of the Learn Python Intermediate course.