python中的三元运算
表达式格式
为真时的结果 if 判定条件 else 为假时的结果
实例
In [15]: a = 10
In [16]: b = 11
In [17]: print('a大于b' if a > b else 'a小于等于b')
a小于等于b
-----
In [23]: hello1 = "welcome to Beijing"
In [24]: hello2 = "Welcome to Caoyang"
In [25]: print(hello1 if address == 'Beijing' else hello2)
welcome to Beijing