python基礎(chǔ)之基本運算符
發(fā)布日期:2021-12-21 08:34 | 文章來源:站長之家
Python基本運算符
算數(shù)運算符

# + - * / % ** // 算數(shù)運算符 # 定義如下運算符 a=7 b=3 print(a+b) print(a-b) print(a*b) print(a/b) print(a%b) print(a//b) # 地板除,相除取整,也可進(jìn)行復(fù)合運算

比較運算符

# == != < > >= <= 比較運算符 a,b=10,5 print(a==b) print(a!=b) print(a<=b) print(a>=b) print(a<b) print(a>b)

邏輯運算符

# and or not 邏輯運算符
# and 條件嚴(yán)格,都為真為真
# or 都為假為假
# not 非 真假切換,只需在前面加上not就可,對于需要取反操作的
a,b,c,d=23,16,26,56
print(a+b>c and c<d)
print(a>b or c<d)
print('--------not-------')
print(a>b)
print(not a>b)

# 優(yōu)先級 # () -> not -> and -> or print (2>1 and 1<4 or 2<3 and 9>6 or 2<4)

賦值運算符

# 賦值運算 (算術(shù)運算的補充) # += -= /= %= **= *= a=10 b=1 c=4 d=5 a+=c print(a) b*=d print(d) d**=c ##數(shù)字為幾即為幾次方 print(d)

總結(jié)
本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關(guān)注本站的更多內(nèi)容!
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。
相關(guān)文章
關(guān)注官方微信