I wanted to know if there is such a thing as a integer even tho it has a .0 decimal at the end. Is it considered a float or an integer?
Asked
Active
Viewed 341 times
0
-
1@lurker - Python isn't statically typed, but it is strongly typed. – TigerhawkT3 Feb 05 '19 at 03:38
-
@TigerjawkT3 thanks for clarifying. I wasn't confident I had the correct term. – lurker Feb 05 '19 at 03:39
-
Somehow a similar question https://stackoverflow.com/questions/54450129/is-there-a-difference-between-an-int-of-5-and-a-float-of-5-0 this kind of question can make sense with a javascript arithmetic implementation in mind. – aka.nice Feb 06 '19 at 22:34
2 Answers
2
It's still a float. For example, do
print(type(1.0))
It prints float
. In general, anything with a decimal point is a float
.

iz_
- 15,923
- 3
- 25
- 40
1
In a programming language, what it means to be a "float" versus an "integer" is to have a particular binary representation in the machine.
In Python specifically, which is not statically typed, if you write x = 1.0
then x
will be a floating point value. It is stored in memory using a floating point representation, such as IEEE-754. If you write x = 1
, then x will be an integer. You are telling Python which representation of 1 you want. If you were writing in C and you write, int x = 1.0
, then x
would still be an integer, since the compiler knows you want x
to be an integer, and the compiler will convert it or generate code to do so.

lurker
- 56,987
- 9
- 69
- 103
-
Strictly speaking, a different behaviour could occur even with same internal representation. The type governs the behavior. Of course, understanding internal representation is important too: float behavior is tightly coupled to the fact that it has a limited number of significand bits. – aka.nice Feb 06 '19 at 22:01