[Tutor] 2.5's new conditional expression syntax

Dick Moores rdm at rcblue.com
Thu Sep 28 19:32:58 CEST 2006


I've been looking hard at 2.5's new conditional expression syntax 
(<http://docs.python.org/whatsnew/pep-308.html>), and didn't 
understand the examples there, so I tried making up my own:

 >>> x = (1 if 2 == 2 else 3)
 >>> x
1
 >>> y = (1 if 2 == 1 else 3)
 >>> y
3
 >>>

But it would help to see an example I could understand that also 
shows the syntax's usefulness. Could someone cook up one for me?

Thanks,

Dick Moores



More information about the Tutor mailing list