[Tutor] getting started

Gregor Lingl glingl@aon.at
Sat Nov 16 01:07:01 2002


Magnus Lycka schrieb:

> At 19:54 2002-11-15 +0100, Gregor Lingl wrote:
>
>> alan.gauld@bt.com schrieb:
>>
>>>> If you are really desperate to run a few lines at once
>>>> in interactive mode, you can do this with a little trick:
>>>>
>>>> >>> if 1 == 1:
>>>>         print "aaa"
>>>>         print "bbb"
>>>>         print "ccc"
>>>
>>>
>>> I like it Magnus! I hadn't thought of that before...
>>
>
> :) Even if Python is easy to learn, we can always learn more
> things. There's no end to the fun! 

Hi Magnus! Thanks for your interesting  and lucid comments - they are
always worth reading, even if lengthy.

>
>
> I've seen the "if 1:" or "if 0:" construct here and there in
> code to make it easy to switch blocks in and out during testing
> and debugging. An alternative to commenting out code I guess.
>
>> Me too! But why not
>>
>> >>> if 1:
>>               print "aaa"
>>               print "bbb"
>
>
> Actually, this is what I would do myself, but it seemed more
> obvious that "if 1==1:" has to be true every time. "if 1:"
> assumes that you understand Python's notion about true and
> false, and I didn't want to explain too many concepts at the
> same time. (I did mention it in the end of the mail though...)

I missed that! Sorry.

Nevertheless: if you write
if 1==1:
don't you suppose this to be easier to understand than
if 0==0:
(or: if 6==6:)? So, apparently, you assume that the reader knows,
that 1 means True in Python.
IMO it's worth to try to avoid, that beginners develop the often
seen habit of using idioms like
if done == 1:  versus if done == 0: etc.
Just a tiny remark. I think, to a large extent it's a  matter of taste.
Regards, Gregor