New to Python: my impression v. Perl/Ruby

Tim Peters tim.one at comcast.net
Tue Jan 20 22:07:37 CET 2004


[Ville Vainio]
> Ints are objects in python too:
>
> >>> a=1
> >>> a.__lshift__(1)
> 2
>
> Though "sending messages" to int literals is a syntax error.

Nope, it's fine.  If you write

    1.__lshift__(1)

it's *parsed* as a float literal ("1.") followed by an identifier
("__lshift__"), and that's not meanignful syntax.  You could, e.g., do
either of these instead:

>>> (1).__lshift__(1)  # parenthesize the int
2
>>> 1 .__lshift__(1)   # put whitespace between int and dot
2
>>>





More information about the Python-list mailing list