coding:utf-8 True/False 1.bool數據類型 a = True b = False print(type(a)) print(type(b)) 2.if語句使用的語法和else語句 if False: print('success') else: print('fail') print ('finished') 比較運算符:‘==’,‘!=’,‘>’,'<','>=','<='################################## a = 1 b = 1 if a == b: print('equal') else: print('not equal') username = input('請輸入用戶名') if username == 'zhiliao': print('恭喜!登錄成功') else: print('抱歉!登錄失敗') blacklist = 'zhiliao' username = input('請輸入用戶名:') if username != 'zhiliao': print('您的用戶名是沒有被加入到黑名單,可以正常使用') else: print('您的用戶名被加入到黑名單,不能正常使用') age=int(input('請輸入年齡:')) if age >= 18: print('已成年') else: print('您年齡未滿18歲不能上網') # 注意 raw_input 和 input 輸出的是str類型的數據,因此使用int轉換數據類型 ################################################################## ######### and ########## or ############### not ################ 1. x and y 只有條件都成立,整體才成立 青年人的年齡范圍:15-24 age = 18 age = int(input('請您輸入年齡')) if age >= 15 and age <= 24: print('您是一個青年人') else: print('您不是青年人') 2. x or y 任意一個條件成立,整體就成立 age = int(input('請您輸入年齡')) if age < 15 or age > 24: print('您不是一個青年人') else: print('您是青年人') 3.not 條件x:如果條件a為true 整體為false 如果條件a為 false 整體為true person1 = '中國人' person2 = '南非' if person1 == '中國人': print('可以上戰艦') else: print('不可以上戰艦') if not person1 == '中國人': print('不可以上戰艦') else: print('可以上戰艦')