首頁 > 後端開發 > Python教學 > python基礎-運算符

python基礎-運算符

巴扎黑
發布: 2016-12-03 09:57:37
原創
997 人瀏覽過

運算子

1、算數運算: +,-,*,/,%,**,//

print (3+2) => 5print (3-2) => 1print (2*4) = > 8print (9/3) => 3print (2**2) => 4print (100%51) => 49print (9//2) => 4

2、比較運算: ==,!=, ,>,=,

print (3==2) => Falseprint (3!=2) => Trueprint (24) =>  True #python3.5中已取消,整合至!=print (9>3) => Trueprint (2 Falseprint (100>=51) => Trueprint (9 False

3、賦值運算: =,+ =,-=,*=,/=,%=,**=,//=

a = 5print (a) => 5a = 5b = 1b += a  # b=b+aprint (b) => 6a = 5b = 1b -= a  # b=b-aprint (b) => -4a = 5b = 1b *= a  # b= b*aprint (b) => 5a = 5b = 1b /= a  # b = b/aprint (b) => 0.2a = 5b = 1b **= a # b = b**aprint (b) => 1a = 5b = 1b %= a # b = b%aprint (b) => 1a = 5b = 1b //= a # b = b//aprint (b) => 0

4、邏輯計算: and, or ,not

a = Trueb = Falseprint (a and b) => False #只有a,b均為真時,才為真print (a or b) => True # 只要a,b中有一個為真時,就為真print (not a) => False # 非真print (not b) => True # 非假

5、成員運算: in, not in

a = [11,22,33,44]
b = 11
c = 123

print (b in a)  >True
print (c not in a)  => True


來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板