osdir.com


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

Explanation of list reference


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