語法:
c = a if a>b else b //如果a>b返回a,否則返回b
可以參看《Python 一些小的古怪寫法 if else for in join》
http://blog.csdn.net/qq_16234613/article/details/64441428
練習
#Hello world program in Python
# -*- coding: utf8 -*-
a,b=1,2
print("a:",a,"b:",b)
a,b=b,a #交換a,b
print("a:",a,"b:",b)
max = a if a>b else b
print("max:",max)
運行結果