True/false integer values

Carsten Gehling carsten at sarum.dk
Fri May 2 08:40:25 EDT 2003


Page 515 of the Cookbook illustrates how the ternary operator

expression ? true-value : false-value

can be simulated in Python. The following example puzzles me:

for i in range(1, 3):
    print "The loop ran %d time%s" % (i, ('', 's')[i != 1])

The tuple ('', 's') has indexes 0 and 1. Does that mean, that the boolean
"true" value in Python is 1 and not -1?

- Carsten






More information about the Python-list mailing list