Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9609cea

Browse files
committed
#3803: fix docs for comparison of unequal types.
1 parent 7cd67cc commit 9609cea

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

Doc/reference/expressions.rst

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,16 +1003,13 @@ pretty).
10031003

10041004
The operators ``<``, ``>``, ``==``, ``>=``, ``<=``, and ``!=`` compare the
10051005
values of two objects. The objects need not have the same type. If both are
1006-
numbers, they are converted to a common type. Otherwise, objects of different
1007-
types *always* compare unequal, and are ordered consistently but arbitrarily.
1008-
You can control comparison behavior of objects of non-builtin types by defining
1009-
a :meth:`__cmp__` method or rich comparison methods like :meth:`__gt__`,
1010-
described in section :ref:`specialnames`.
1011-
1012-
(This unusual definition of comparison was used to simplify the definition of
1013-
operations like sorting and the :keyword:`in` and :keyword:`not in` operators.
1014-
In the future, the comparison rules for objects of different types are likely to
1015-
change.)
1006+
numbers, they are converted to a common type. Otherwise, the ``==`` and ``!=``
1007+
operators *always* consider objects of different types to be unequal, while the
1008+
``<``, ``>``, ``>=`` and ``<=`` operators raise a :exc:`TypeError` when
1009+
comparing objects of different types that do not implement these operators for
1010+
the given pair of types. You can control comparison behavior of objects of
1011+
non-builtin types by defining rich comparison methods like :meth:`__gt__`,
1012+
described in section :ref:`customization`.
10161013

10171014
Comparison of objects of the same type depends on the type:
10181015

0 commit comments

Comments
 (0)