Ternary operators are known as conditional expressions in Python. You can use conditional expressions as follows:
True if True else False
E.g.
>>> from datetime import datetime >>> str(datetime.today().second) if datetime.today().second>9 else '0'+str(datetime.today().second)'59'>>> str(datetime.today().second) if datetime.today().second>9 else '0'+str(datetime.today().second)'00'>>> str(datetime.today().second) if datetime.today().second>9 else '0'+str(datetime.today().second)'02'
>>> from datetime import datetime
>>> str(datetime.today().second) if datetime.today().second>9 else '0'+str(datetime.today().second)
'59'
'00'
'02'