+ 1

Why why we say that in python an int or float variables are objects???

I agree that when we create lists or Tuples or even dictionaries we are creating an objects of these data structures Because they are already built in python Which means we are creating objects . But I can’t understands that floats and int variables are objects Normally they are called primitive data types

2nd Mar 2021, 6:08 PM
Amal Gil
Amal Gil - avatar
4 Answers
+ 2
Because they are objects of a class. You can try it with print(type(1)) as an example, and you get that 1 is of class int.
2nd Mar 2021, 6:50 PM
Per Bratthammar
Per Bratthammar - avatar
+ 1
they are primitive wrapped in object ;)
2nd Mar 2021, 6:49 PM
visph
visph - avatar
+ 1
There are a class in python called int and there are a class called float so we create object from int or float classes.
2nd Mar 2021, 6:53 PM
HBhZ_C
HBhZ_C - avatar