+ 1
implicit convertion in python
Why have to convert the integer to a float when 8/2? I suppose it might be easier for computer to operate in integer than float.
3 Antworten
+ 3
It just is so.
True division "/" (almost) always gives the result as a double floating number.
But for whole number division you can use:
Floor division "//", which gives it's result (almost) always as a whole number (Can be either float and integer depending on the operands)
I added "almost" because in case of ZeroDivisionError nothing is returned.
+ 4
The / division always gives float value, regardless if the result is integer or not.
You can use also 8//2 that is the floor division operator, if both operands are integers then the result will be also guaranteed integer in Python3
+ 1
Thankx. It helps me a lot.