On Fri, 4 Jun 2010 03:10:41 am Alan Gauld wrote: > "Tino Dai" <obe...@gmail.com> wrote > > > Is there a way to express this: > > isThumbnail = False > > if size == "thumbnail": > > isThumbnail = True > > > > like this: > > [ isThumbnail = True if size == "thumbnail" isThumbnail = > > False ] > > Bob showed one way, you could also do: > > isThumbnail = True if size == "thumbnail" else False
That is technically correct, you could do that. That's a good example of the syntax of the `if` expression, but it's a bad example of where to use it: (1) it only works in Python 2.5 or better; and (2) experienced Python programmers will laugh at you :) with all due respect to Alan who suggested it. It really is an unnecessarily complicated and verbose way of doing a simple assignment, nearly as bad as writing this: if len(mystring) == 0: n = 0 else: n = len(mystring) instead of just n = len(mystring) -- Steven D'Aprano _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor