讀古今文學網 > 父與子的編程之旅:與小卡特一起學Python > 7.8 使用 or >

7.8 使用 or

or 關鍵字也是用來把多個條件放在一起。如果使用 or,只要任意一個條件為真,就會執行代碼塊。

color = raw_input("Enter your favorite color: ")if color == "red" or color == "blue" or color == "green":    print "You are allowed to play this game."else:    print "Sorry, you can't play the game."