Hint: You can adjust the default video playback speed in your account settings.
Sorry! Looks like there’s an issue with video playback 🙁 This might be due to a temporary outage or because of a configuration issue with your browser. Please see our video player troubleshooting guide to resolve the issue.

Floats

Give Feedback

Comments & Discussion

Zarata on March 30, 2020

I’m appreciating your skill as a teacher in particular, and the quality and ‘excellent’ attitude of Real Python as a whole. You all have made a monster, though: all of the encouragement encourages me to participate and post this point! I’m a long-time programmer now wishing to pick up Python, and I’m a personality type which tends to take some point and run to try variations “before their time” – perhaps before allowing time for explanation of other details in their good order. I guess I didn’t learn … when they said “brains”, I thought they said “trains”, so I ran to catch one ....

At any rate, I’ve noted by midway this section, or a bit further, that you’ve referred to ‘//’ both as an “integer divide” and as a “floor divide”. You’ve also used the words – in a context –

it [the result of ‘//’] will always be an integer result which may not be what you are looking for.

So, I ran off in a direction. As I meandered, I discovered the ‘//’ result (at least in v3.8.2) is not always an integer. The dynamically typed result of ‘//’ depends upon the argument types with float dominating:

>>>c=10
>>>d=3
>>>e=10.0
>>>f=3.0
# int // int
>>>c//d
3
# float // float
>>>e//f
3.0
# int // float
>>>c//f
3.0
# float // int
>>>e//d
3.0

’//’ in v3.8.2 is apparently always “floor divide”. The integer result contrast of ‘//’ to the always float result of ‘/’ exists only for the special case ‘int // int’.

Perhaps this is a v.3.8 change from v3.6???

Should I post again, I’ll be briefer. :) Thanks for your instruction!

Become a Member to join the conversation.