Explanation of list reference

Chris Angelico rosuav at gmail.com
Sun Feb 16 11:18:17 CET 2014


On Sun, Feb 16, 2014 at 7:40 PM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> There are three simple ways to get the effect that you want:
>
> py> x = 1; x.__str__()  # don't use a literal
> '1'
> py> (1).__str__()  # parenthesize the literal
> '1'
> py> 1 .__str__()  # offset it from the dot with a space
> '1'

Four:
>>> 0o1.__str__() # use a literal notation that doesn't allow floats
'1'

ChrisA



More information about the Python-list mailing list