By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,235 Members | 1,022 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,235 IT Pros & Developers. It's quick & easy.

Comparing objects to built-in literals

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

Let's say I have a class which does not define __cmp__ or any of the
rich comparison functions and let x be an instance of this class, then
if I do:

x < 2
or x < ['hello']

I get True everytime. Now, I know that when no __cmp__ etc. is defined,
comparison of objects is done on identity (i.e. address), but what is
going on with literals like in these cases?

Thanks,

Richard Hayden.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFCMgNw1y4M4bx2DkwRAusqAJ41770hdItCwSX4GZ4Ifq WGFyY8dQCbBDaq
qPV1cZUrCnapcCY+driN2jU=
=9HT3
-----END PGP SIGNATURE-----
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
The documentation tells that objects of different type are ordered
arbitrailiy but consistently. You compare a class with an integer and a
list, see : http://www.python.org/doc/2.3.5/lib/comparisons.html

Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.