Python 3 integer division
Try this:
a = 1
b = 2
int_div = a // b
Related videos on Youtube
Megatron
BY DAY: Mining energon, battling Autobots, planning triumphant return to Cybertron. FOR FUN: r analyses of any publicly available data, python for ML, git for all of the above "If something cannot go on forever, it will stop." - Herbert Stein's Law "The perfect is the enemy of the good." "A camel is a horse designed by committee." "All models are wrong, but some are useful." - George Box "There are three kinds of lies: lies, damned lies and statistics." "If you torture the data long enough, it will confess to anything." "The enemy of art is the absence of limitations." - Orson Welles "If you're explaining, you're losing." "Excessive civility without adequate candor means that everyone feels good but not much is really being discussed. Candor is more proactive." - Todd Dewett "Five minutes of extra care saves an hour" "I have not failed. I've just found 10,000 ways that won't work." - Thomas Edison
Updated on January 31, 2022Comments
-
Megatron over 2 years
In Python 3 vs Python 2.6, I've noticed that I can divide two integers and get a float. How do you get the Python 2.6 behaviour back?
Is there a different method to get int/int = int?
-
falsetru over 10 yearsUse
//
(floor division) instead of/
(true division). -
Seng Cheong over 10 yearsPEP 238 introduced the
//
floor division operator.
-
-
Kyle Strand over 8 yearsNote that
//
is available in Python2 as well (since 2.2, I believe). -
asmaier over 6 yearsNote that
1.0 // 2
and1 // 2.0
maybe surprisingly return a float with value0.0
. -
Thorham almost 5 yearsFloor divisions are NOT integer divisions. A floor division will return -2 for -3 / 2, while an integer division should return -1 (there's no floor or ceil in integer land).