This trick is neat and potentially useful although maybe not very Pythonic:
txt = "two"
val = (
1 if txt == "one" else
2 if txt == "two" else
3 if txt == "three" else
0)
print val
The following form can be used instead:
txt = "three"
val = \
1 if txt == "one" else \
2 if txt == "two" else \
3 if txt == "three" else \
0
print val