osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Explanation of list reference


On Sun, Feb 16, 2014 at 1:28 AM, Ian Kelly <ian.g.kelly at gmail.com> wrote:
>
> On Feb 16, 2014 1:11 AM, "Marko Rauhamaa" <marko at pacujo.net> wrote:
>> Case in point, if everything is a reference, how come:
>>
>>    >>> "hello".__str__()
>>    'hello'
>>    >>> 1.__str__()
>>    SyntaxError: invalid syntax
>
> You need parentheses around the 1. Otherwise you confuse the lexer, which
> thinks you're starting a float literal.
>
>>>> (1).__str__()
> '1'

Or if the parentheses bother you, you can also just toss in some whitespace:

>>> 1 .__str__()
'1'