Question | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 3

Question

Why it is integer? For dividing it turns float number

22nd Nov 2021, 1:15 PM
ŠšŃŠµŠ½Šøя ŠšŃ€Š°ŃŠ½Š¾Š²Š°
3 Respostas
+ 4
Thats how division works in python. Always returns a float
22nd Nov 2021, 1:29 PM
Slick
Slick - avatar
+ 2
22nd Nov 2021, 1:32 PM
Paul K Sadler
Paul K Sadler - avatar
+ 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.
24th Nov 2021, 10:40 AM
NoBody
NoBody - avatar