0

Memory usage of float and integer

Hi there, Iā€™m kind of new in Python and I have a question: Something I donā€™t understand is: if we know float take more space in memory rather than integers, why some results from simple operations in Python are displayed in floating point number? For instance: 10 / 2 will give 5.0 which takes more memory rather than 5 which one takes less.

24th Jun 2020, 8:01 PM
Staline Ngoma
3 Answers
+ 4
In other languages like C or Java, if you divide an int by an int, you get a result with the decimals cut off. That's nothing special for computer people, but regular people would be confused, because in school they learned that 5/2 is 2.5. I often get the impression that Python is specifically designed in a way that makes most sense for people who aren't so familiar with computers. For regular people writing a bit of practical code, nothing too big, the small byte price of having a double isn't anything they'd want to worry or even think about. *All* the datatypes are bigger in memory cost than in other languages. But you get a lazy convenience in return. No wonder Python's popular as a beginner's language and gains popularity (probably often with folks who wouldn't have messed with programming otherwise).
24th Jun 2020, 8:33 PM
HonFu
HonFu - avatar
+ 1
nice #swim i do understand the concept better
24th Jun 2020, 8:16 PM
Staline Ngoma