布爾類型
'''
作用:True與False,用於條件判斷
定義:
tag=True
tag=False
print(10 > 3)
print(10 < 3)
'''
基本運算符
1、算數運算符
print(10 + 3)
print(10 - 3)
print(10 * 3)
print(10 / 3) # 保留小數部分
print(10 // 3) # 只保留整數部分
print(10 % 3) # 取余數,取模
print(10 ** 3)
2、比較運算符:
x=10
y=10
print(x == y) # =一個等號代表的是賦值
x=3
y=4
print(x != y) # 不等於
x=3
y=4
print(x > y) # False
print(x < y) # True
print(x >= y) # False
print(x <= y) # True
print(10 <= 10) # True
3、賦值運算符
age=18
age=age + 1 # 賦值運算
age+=1 # 賦值運算符,age=age+1
print(age)
age*=10 # age=age*10
age**=10 # age=age**10
age/=10 # age=age/10
age//=10 # age=age//10
age-=10 # age=age-10
print(age)
4、邏輯運算符
and: 邏輯與,and是用來連接左右兩個條件,只有在左右兩個條件同時為True,最終結果才為True,但凡有一個為False,最終結果就為False
print(10 > 3 and True)
print(10 < 3 and True and 3 > 2 and 1==1)
or:邏輯或,or是用來連接左右兩個條件,但凡有一個條件為True,最終結果就為True,除非二者都為False,最終結果才為False
print(True or 10 > 11 or 3 > 4)
print(False or 10 > 11 or 3 > 4)
print(False or 10 > 9 or 3 > 4)
False or (True and True)
False or True
res=(True and False) or (10 > 3 and (3 < 4 or 4==3))
print(res)
not:把緊跟其后那個條件運算的結果取反
print(not 10 > 3)
False or (False and False)
False or False
res=(True and False) or (not 10 > 3 and (not 3 < 4 or 4==3))
print(res)
if判斷
'''
代碼塊:
1、代碼塊指的是同一級別的代碼,在python中用縮進相同的空格數(除了頂級代碼塊無任何縮進之外,其余代碼塊都是在原有的基礎上縮進4個空格)來標識同一級的代碼塊
2、同一級別的代碼塊會按照自上而下的順序依次運行
'''
'''
語法1:
if 條件: # 條件成立的情況下會運行子代碼塊
子代碼1
子代碼2
子代碼3
...
'''
'''
print('sdsd')
x=1123
y=456
l=[1,2,3,]
print(x,y,l)
if 10 > 3:
print(1)
print('結束啦')
age = 73
age = 18
sex='female'
is_beautiful=True
if age > 16 and age < 20 and sex=='female' and is_beautiful:
print('開始表白。。。')
print('我是if之后的代碼,是頂級代碼')
'''
'''
語法2:
if 條件: # 條件成立的情況下會運行子代碼塊
子代碼1
子代碼2
子代碼3
...
else: # 條件不成立的情況下會運行else包含的子代碼塊
子代碼1
子代碼2
子代碼3
...
'''
'''
age = 73
# age = 18
sex='female'
is_beautiful=True
if age > 16 and age < 20 and sex=='female' and is_beautiful:
print('開始表白。。。')
else:
print('阿姨好,我們不太合適,還是做朋友吧。。。')
print('我是if之后的代碼,是頂級代碼')
'''
'''
語法3:
if 條件1: # 條件1成立的情況下會運行子代碼塊
子代碼1
子代碼2
子代碼3
...
elif 條件2: # 條件2成立的情況下會運行子代碼塊
子代碼1
子代碼2
子代碼3
...
elif 條件3: # 條件3成立的情況下會運行子代碼塊
子代碼1
子代碼2
子代碼3
...
......
else: # 上述條件都不成立的情況下會運行else包含的子代碼塊
子代碼1
子代碼2
子代碼3
...
'''
'''
示范: 如果:成績>=90,那么:優秀
如果成績>=80且<90,那么:良好
如果成績>=70且<80,那么:普通
其他情況:很差
score=input('請輸入您的分數進行查詢:') # score="abc"
if score.isdigit(): # "99".isdigit()
score=int(score) # 把純數字的字符串轉換成整型,score=int("99")
if score >= 90:
print('成績的級別為:優秀')
elif score >= 80:
print('成績的級別為:良好')
elif score >= 70:
print('成績的級別為:普通')
else:
print('成績的級別為:很差')
else:
print('必須輸入純數字')
'''