operator overloading on built-ins

R

r.grimm

Hallo,
could you explaint me the difference between the two following
statements.


Python 2.5 (r25:51908, Oct 7 2006, 23:45:05)
[GCC 3.3.5 20050117 (prerelease) (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information. File "<stdin>", line 1
1.__cmp__(10)
^
SyntaxError: invalid syntax

The first works as expect, but the second.

Regards Rainer
 
M

Marc 'BlackJack' Rintsch


As the dot is an operator like ``+`` or ``/`` you can also add spaces to
avoid the ambiguity:

In [493]: 1 . __cmp__(10)
Out[493]: -1

In [494]: 1 .__cmp__(10)
Out[494]: -1

Ciao,
Marc 'BlackJack' Rintsch
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top