default behavior
Peter Otten
__peter__ at web.de
Thu Aug 12 16:52:03 EDT 2010
David Niergarth wrote:
> [Oops, now complete...]
> Peter Otten <__pete... at web.de> wrote:
>>
>> > >>> 1 .conjugate()
>>
> This is a syntax I never noticed before. My built-in complier (eyes)
> took one look and said: "that doesn't work."
(1).conjugate may hurt a little less. Anyway, the space is only needed for
the tokenizer that without it would produce a float immediately followed by
a name.
> Has this always worked in
> Python but I never noticed?
Probably.
> I see other instance examples also work.
>
> >>> '1' .zfill(2)
> '01'
> >>> 1.0 .is_integer()
> True
>
> and properties
>
> >>> 1.0 .real
> 1.0
>
> Curiously, a float literal works without space
>
> >>> 1.0.conjugate()
> 1.0
>
> but not an int.
>
> >>> 1.conjugate()
> File "<stdin>", line 1
> 1.conjugate()
> ^
> SyntaxError: invalid syntax
>
> Anyway, I didn't realize int has a method you can call.
>
> --David
More information about the Python-list
mailing list