Use cases for del

Steven D'Aprano steve at
Thu Jul 7 10:24:58 CEST 2005

Ron Adam wrote:

> Why would you want to use None as an integer value?
> If a value isn't established yet, then do you need the name defined? 
> Wouldn't it be better to wait until you need the name then give it a value?

Er, maybe I'm misunderstanding something here, but 
surely the most obvious case is for default and special 
function arguments:

def count_records(record_obj, start=0, end=None):
     if end == None:
         end = len(record_obj)
     if start == None:  # this is not the default!
         # start at the current position
         start = record_obj.current
     n = 0
     for rec in[start:end]:
         if not rec.isblank():
             n += 1
     return n

which you call with:

# current position to end
count_records(myRecords, None)
# start to end
# start to current position
count_records(myRecords, end=myRecords.current)


More information about the Python-list mailing list