Explanation of list reference

Ian Kelly ian.g.kelly at gmail.com
Sun Feb 16 09:28:34 CET 2014


On Feb 16, 2014 1:11 AM, "Marko Rauhamaa" <marko at pacujo.net> wrote:
>
> Marko Rauhamaa <marko at pacujo.net>:
>
> > Conceptually, the "everything is a reference" and the "small"/"big"
> > distinction are equivalent (produce the same outcomes). The question
> > is, which model is easier for a beginner to grasp.
>
> 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'
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140216/c85f3fd2/attachment.html>


More information about the Python-list mailing list