+ 3
Question
Why it is integer? For dividing it turns float number
3 odpowiedzi
+ 4
Thats how division works in python. Always returns a float
+ 2
Ксения Краснова
5 / 2 = 2.5 float
5 // 2 = 2 integer
+ 2
Python simply lets you declare a variable without any need of telling the data type. If you declare a variable like
x = 10
then it is an integer, as the compiler itself understand. But if you work upon it using division,
x=x/4
The answer is 2.5 and the compiler itself converts it to the required type that is float, unlike other languages like C++ where it rounds it off to make it an integer.
So, that should not be a problem.
If you want to get an integer as a result, you can convert it explicitly.
🙂A smiley for you.