Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
ab782dd6
Kaydet (Commit)
ab782dd6
authored
Ock 18, 2001
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Document rich comparisons.
üst
67345eb0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
5 deletions
+42
-5
ref3.tex
Doc/ref/ref3.tex
+42
-5
No files found.
Doc/ref/ref3.tex
Dosyayı görüntüle @
ab782dd6
...
...
@@ -133,9 +133,10 @@ Its truth value is false.
\item
[NotImplemented]
This type has a single value. There is a single object with this value.
This object is accessed through the built-in name
\code
{
NotImplemented
}
.
Binary number methods may return this value if they do not implement the
operation for the types of operands provided. The interpreter will then
try the reverse operation. Its truth value is true.
Numeric methods and rich comparison methods may return this value if
they do not implement the operation for the operands provided. (The
interpreter will then try the reflected operation, or some other
fallback, depending on the operator.) Its truth value is true.
\ttindex
{
NotImplemented
}
\obindex
{
NotImplemented@
{
\texttt
{
NotImplemented
}}}
...
...
@@ -943,8 +944,44 @@ expression: a more convenient or concise representation may be used
instead. The return value must be a string object.
\end{methoddesc}
\begin{methoddesc}
[object]
{__
lt
__}{
self, other
}
\methodline
[object]
{__
le
__}{
self, other
}
\methodline
[object]
{__
eq
__}{
self, other
}
\methodline
[object]
{__
ne
__}{
self, other
}
\methodline
[object]
{__
gt
__}{
self, other
}
\methodline
[object]
{__
ge
__}{
self, other
}
\versionadded
{
2.1
}
These are the so-called ``rich comparison'' methods, and are called
for comparison operators in preference to
\method
{__
cmp
__
()
}
below.
The correspondence between operator symbols and method names is as
follows:
\code
{
\var
{
x
}
<
\var
{
y
}}
calls
\code
{
\var
{
x
}
.
__
lt
__
(
\var
{
y
}
)
}
,
\code
{
\var
{
x
}
<=
\var
{
y
}}
calls
\code
{
\var
{
x
}
.
__
le
__
(
\var
{
y
}
)
}
,
\code
{
\var
{
x
}
==
\var
{
y
}}
calls
\code
{
\var
{
x
}
.
__
eq
__
(
\var
{
y
}
)
}
,
\code
{
\var
{
x
}
!=
\var
{
y
}}
and
\code
{
\var
{
x
}
<>
\var
{
y
}}
call
\code
{
\var
{
x
}
.
__
ne
__
(
\var
{
y
}
)
}
,
\code
{
\var
{
x
}
>
\var
{
y
}}
calls
\code
{
\var
{
x
}
.
__
gt
__
(
\var
{
y
}
)
}
, and
\code
{
\var
{
x
}
>=
\var
{
y
}}
calls
\code
{
\var
{
x
}
.
__
ge
__
(
\var
{
y
}
)
}
.
These methods can return any value, but if the comparison operator is
used in a Boolean context, the return value should be interpretable as
a Boolean value, else a
\exception
{
TypeError
}
will be raised.
By convention,
\code
{
0
}
is used for false and
\code
{
1
}
for true.
There are no reflected (swapped-argument) versions of these methods
(to be used when the left argument does not support the operation but
the right argument does); rather,
\method
{__
lt
__
()
}
and
\method
{__
gt
__
()
}
are each other's reflection,
\method
{__
le
__
()
}
and
\method
{__
ge
__
()
}
are each other's reflection, and
\method
{__
eq
__
()
}
and
\method
{__
ne
__
()
}
are their own reflection.
Arguments to rich comparison methods are never coerced. A rich
comparison method may return
\code
{
NotImplemented
}
if it does not
implement the operation for a given pair of arguments.
\end{methoddesc}
\begin{methoddesc}
[object]
{__
cmp
__}{
self, other
}
Called by all comparison operations. Should return a negative integer if
Called by comparison operations if rich comparison (see above) is not
defined. Should return a negative integer if
\code
{
self < other
}
, zero if
\code
{
self == other
}
, a positive integer if
\code
{
self > other
}
. If no
\method
{__
cmp
__
()
}
operation is defined, class
instances are compared by object identity (``address'').
...
...
@@ -1288,7 +1325,7 @@ called to implement the binary arithmetic operations (\code{+},
\code
{
-
}
,
\code
{
*
}
,
\code
{
/
}
,
\code
{
\%
}
,
\function
{
divmod()
}
\bifuncindex
{
divmod
}
,
\function
{
pow()
}
\bifuncindex
{
pow
}
,
\code
{
**
}
,
\code
{
<<
}
,
\code
{
>>
}
,
\code
{
\&
}
,
\code
{
\^
}
,
\code
{
|
}
) with re
versed
operands. These
\code
{
\&
}
,
\code
{
\^
}
,
\code
{
|
}
) with re
flected (swapped)
operands. These
functions are only called if the left operand does not support the
corresponding operation. For instance, to evaluate the expression
\var
{
x
}
\code
{
-
}
\var
{
y
}
, where
\var
{
y
}
is an instance of a class that
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment