On Thu, 6 Feb 2003, Shane Holloway (IEEE) wrote: > I was thinking that the semantics of "and" & "or" are the replacement > for the trinary operator? Since these operations always return the last > evaluated subexpression (the same subexpression that short-circuits the > evaluation), they can be used as Gerald outlines above. Unfortunately, this doesn't work if the result is false. For example, here's a common idiom i use in C: printf("Read %d file%s.", count, count == 1 ? "" : "s"); If you try to translate this to Python using "and"/"or": print 'Read %d file%s.' % (count, count == 1 and '' or 's') ...it doesn't work, because the empty string is false. Alas... -- ?!ng
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4