[Tutor] am I missing another simpler structure?

Juan Shen orion_val at 163.com
Thu Dec 16 11:40:01 CET 2004


Kent Johnson wrote:

> Brian van den Broek wrote:
>
>> I've begun to wonder if I am overlooking a improvement similar to 
>> that in DogWalker's suggestion. As an example of the sort of thing I 
>> have been doing:
>>
>> import datetime
>> def is_leap_year(year):
>>     '''-> boolean
>>
>>     Returns True or False as year is, or is not, a leap year.
>>     '''
>>     is_leap = True
>>     try:
>>         datetime.date(year, 2, 29)
>>     except ValueError:
>>         is_leap = False
>>     return is_leap
>
>
> I would write
> def is_leap_year(year):
>     try:
>         datetime.date(year, 2, 29)
>         return True
>     except ValueError:
>         return False
>
> Kent
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
Yeah, I support Kent.  Brian's code is obviously C style,  define a 
variable and give it an origin value, then use it, modify its value and 
so on.  If you choose Python, you should adapt to it that variable 
needn't to be defined specificly before being used!
    Juan Shen



More information about the Tutor mailing list