some problems for an introductory python test

Hope Rouselle hrouselle at jevedi.com
Wed Aug 11 08:11:33 EDT 2021


Greg Ewing <greg.ewing at canterbury.ac.nz> writes:

> On 11/08/21 3:22 pm, Terry Reedy wrote:
>> 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.
>>  >>> if3: print('yes!')
>> yes!
>
> That may not be doing what you think it's doing. Consider also
>
>>>> if0: print('yes!')
> yes!

So, yes, that's puzzling.

>>> 0 == False
True
>>> if0: print("yes")
yes
>>> if(0): print("yes")

>>>

What's going on there?


More information about the Python-list mailing list