basic questions on cmp, < and sort
bignose+hates-spam at benfinney.id.au
Thu Oct 26 04:44:10 CEST 2006
Schüle Daniel <uval at rz.uni-karlsruhe.de> writes:
> first question
> In : cmp("ABC",['A','B','C'])
> Out: 1
> against what part of the list is the string "ABC" compared?
Why "part"? There are two objects; they are compared to each other.
How this comparison is implemented is a matter handled by the class of
> second question
> In : class X(object):
> .....: pass
> In : X() < X()
> [... differing results ...]
> class X does not implement < and cmp
> what is this comparision is based on?
Classes can implement various functions to allow comparisons to work:
In the absence of those, the comparison's result is (I believe)
implementation-dependent -- which means, "don't rely on any particular
> third question
> sort([[1,2,3],["ABC"],['Z','A'], X(), 4)
>>> sort([[1,2,3],["ABC"],['Z','A'], X(), 4)
File "<stdin>", line 1
sort([[1,2,3],["ABC"],['Z','A'], X(), 4)
SyntaxError: invalid syntax
Care to give an actual example?
\ "I went to the hardware store and bought some used paint. It |
`\ was in the shape of a house." -- Steven Wright |
More information about the Python-list