some problems for an introductory python test
Terry Reedy
tjreedy at udel.edu
Tue Aug 10 23:22:43 EDT 2021
On 8/10/2021 5:27 PM, Hope Rouselle wrote:
> Terry Reedy <tjreedy at udel.edu> writes:
>
>> On 8/10/2021 9:15 AM, Hope Rouselle wrote:
>>>>>> 2.__add__(3)
>>> SyntaxError: invalid syntax
>>> But then I tried:
>>>
>>>>>> (2).__add__(3)
>>> 5
>>
>> Add a space is easier.
>>>>> 2 .__add__(3)
>> 5
>>>>>
>
> Hah. That's brilliant! So cool.
Python is a little looser about whitespace than one might expect from
reading 'normal' code when the result is unambiguous in that it cannot
really mean anything other than what it does. Two other examples:
>>> if3: print('yes!')
yes!
>>> [0] [0]
0
--
Terry Jan Reedy
More information about the Python-list
mailing list