[Python-Dev] "and" and "or" operators in Py3.0

Jonathan LaCour jonathan-lists at cleverdevil.org
Tue Sep 20 02:13:05 CEST 2005

> P.S.  Simplifying "and" and "or" may create a need to introduce a
> conditional operator but that is a discussion for another day.

While I don't disagree with some of your main points, I do think that  
your proposal would eliminate a natural and easy to understand use of  
the current behavior of "or" that I tend to use quite a bit.  Your  
proposal would break a lot of code, and I can't think of a better  
"conditional operator" than the one thats already there.

I often find myself using 'or' to conditionally select a meaningful  
value in the absence of a real value:

     person = Person.fetch(id=5)
     name = person.name or 'John Doe'
     birth_date = person.birth_date or '00-00-0000'
     ssn = person.social_security or 'not provided'
     logger.log_msg('%s born on %s with SSN %s' % (name, birth_date,  

To me, its just as natural as:

     { 'key' : value }.get('not_there', 'default')

but more general purpose.  I like the current behavior, and I think  
it makes a whole lot of sense.

Jonathan LaCour

More information about the Python-Dev mailing list