[Tutor] How to enable pausing my stop_watch.py ?

Dick Moores rdm at rcblue.com
Fri Jul 9 22:24:45 CEST 2004


Alan Gauld wrote at 12:04 7/7/2004:
> > hours = raw_input("Enter the number of hours to time ")
> > if hours == "":
> >      h_seconds = 0
> > else:
> >      h_seconds = 3600 * int(hours)
>
>   h_seconds = (hours and 3600*int(hours)) or 0  # shorter but more
>obscure
>
>Works like this:
>Only evaluate 3600*hours if hours NOT ""
>If result is False(ie hours was "") then evaluate
>second part of OR - ie 0

I'm very glad to know about these uses of "and" and "or", but why is your 
way better? Is fewer lines better? Is it faster? More Pythonesque? (I'm 
not defending my code; I'd just like to know.)

Thanks,

Dick Moores






More information about the Tutor mailing list