Do you know that there is clean way of doing what C-language ternary operator ? does in Python's recent versions.
It is if with special twist. The syntax is:
'The value if true' if <condition> else 'Value when false'
Values can be any type. You can put this structure to replace single value.
In this classic number guess game version we practise using the structure even in a nested way. This is not maybe so advisable general way, as it is less clear than many print statements in normal if statement.
Anyway, this came first to my mind as demonstration of this, as I learned about this statement form myself only today. I have used
or to simulate the form before.
Edited 4 Years Ago by pyTony