abs(x%y) < abs(y)
is true mathematically, for floats it may not be true
numerically due to roundoff. For example, and assuming a platform on which a
Python float is an IEEE 754 double-precision number, in order that
-1e-100 % 1e100
have the same sign as
, the computed result is
-1e-100 + 1e100
, which is
numerically exactly equal to
. The function
returns a result whose
sign matches the sign of the first argument instead, and so returns
case. Which approach is more appropriate depends on the application.
If x is very close to an exact integer multiple of y, it’s possible for
one larger than
due to rounding. In such cases, Python returns the latter
result, in order to preserve that
divmod(x,y) * y + x % y
be very close to
While comparisons between unicode strings make sense at the byte level, they may
be counter-intuitive to users. For example, the strings
compare differently, even though they both represent the same
unicode character (LATIN CAPITAL LETTER C WITH CEDILLA). To compare strings
in a human recognizable way, compare using
 The implementation computes this efficiently, without constructing lists or sorting.
Earlier versions of Python used lexicographic comparison of the sorted (key, value)
lists, but this was very expensive for the common case of comparing for equality. An
even earlier version of Python compared dictionaries by identity only, but this caused
surprises because people expected to be able to test a dictionary for emptiness by
comparing it to
Due to automatic garbage-collection, free lists, and the dynamic nature of
descriptors, you may notice seemingly unusual behaviour in certain uses of the
operator, like those involving comparisons between instance methods, or constants.
Check their documentation for more info.
operator is also used for string formatting; the same precedence applies.
The power operator
binds less tightly than an arithmetic or bitwise unary operator
on its right, that is,
Python » Python v2.7.6 documentation » The Python Language Reference »
1990-2013, Python Software Foundation.
The Python Software Foundation is a non-profit corporation. Please donate.
Last updated on Nov 10, 2013. Found a bug
Created using Sphinx