1. 程式人生 > >Python if,elif,else。and,or,not

Python if,elif,else。and,or,not

 

demo.py(if,elif,else):


holiday_name = "生日"

if holiday_name == "情人節":
    print("買玫瑰")
    print("看電影")
elif holiday_name == "平安夜":
    print("買蘋果")
    print("吃大餐")
elif holiday_name == "生日":
    print("買蛋糕")
else:
    print("每天都是節日啊")

demo.py(and,or 拼接多個邏輯判斷):


age = 12

if age >= 0 and age <= 120:
    print("年齡正確")
else:
    print("年齡不正確")

demo.py(not 取反):


is_employee = False

if not is_employee:
    print("非本公司人員,請勿入內")