Python_條件測試

1. 基本用法
# _*_ coding:utf8 _*_
# 條件測試

cars = ['ad', 'bm', 'bc', 'fll']

for car in cars:
    if car == 'ad':
        print(car.upper())
    else:
        print(car.title())
# 賦值
car = 'ad'
# 判斷  爲真輸出True 爲假輸出False
print(car == 'ad')

car = 'bm'
print(car == 'bb')

car = 'BM'
print(car == 'bm')

print(car.lower() == 'bm')

if car != 'BM':
    print("this is my option")

# 比較數字

number = 14
print(number >= 15)

# 多條件檢查  and   or
age_0 = 19
age_1 = 20

# false
print(age_0 >= 20 and age_1 >= 20)
# true
print(age_0 >= 20 or age_1 >= 20)

# 檢查特定值是否包含在列表中 使用關鍵字 in

students = ['zhangqi','qiyongshuai','chengjian','renhengyao']
print('zhangqi' in students)
print('zhanglu' in students)

# 檢查特定值是否不包含在列表中  關鍵字爲 not in

banned_users = ['lb','dp','tym','mhr']
user = 'zq'

if user not in banned_users:
    print("hello")

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章