> That's very clear. Thanks, Wesley.
> And if you wanted to know which is smaller, x or y:
>
> x = 8**9
> y = 9**8
> smaller = "x" if x < y else "y"
> print smaller, "is smaller"
>
> I think I'm getting the hang of it!

your example is correct.  if you had a background in C programming,
you would recognize the syntax of the "ternary operator:"

smaller = x < y ? x : y

guido chose Python's syntax...

smaller = x if x < y else y

... because "smaller = x" would be the typical case (the conditional
expression usually should evaluate to True), and evaluation to False
is a special (or inoften) case.  if this is true, then the syntax is
easier to follow this way.  there is some explanation of this in the
PEP and CLP threads.


> BTW I'm told your book will arrive on my front porch in a couple of
> days. I'm looking forward to it!  (<http://tinyurl.com/f22uu>)

sigh... i still haven't gotten mine from the publisher yet.  i think
you'll get yours before i get mine!!!

cheers,
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
    http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to