程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

[learn Python from simple to deep] seven types of operators

編輯:Python

One 、 Introduce

Python The operators in are mainly divided into arithmetic operators 、 Compare ( Relationship ) Operator 、 Assignment operator 、 Logical operators 、 An operator 、 The membership operator and the identity operator share 7 Categories: , Operators are also determined by priority .

Two 、 give an example

1. Arithmetic operator

>>> 5 + 4
9
>>> 4.3 - 2
2.3
>>> 3 * 7
21
>>> 2 / 4
0.5
>>> 2 // 4
0
>>> 17 % 3
2
>>> 2 ** 5
32

2. Comparison operator

Python Comparison ( Relationship ) Operator of 6 individual

>>> a =1
>>> b =2
>>> print(a == b)
False
>>> print(a != b)
True

3. Assignment operator

Python The assignment operators of are 8 individual

>>> a =2
>>> b =3
>>> a+=b
>>> print(a)
5
>>> a-=b
>>> print(a)
2

4. Logical operators

Python The logical operators of are 3 individual

>>> a =True
>>> b =False
>>> print(a and b)
False
>>> print(a or b)
True
>>> print(not(a and b))
True

5. An operator

Python Bitwise operators of 6 individual

>>> a=55 #a=0011 0111
>>> b=11 #b=0000 1011
>>> print(a&b)
3
>>> print(a|b)
63

6. member operator

Python The member operators of are 2 individual

>>> a=1
>>> b=20
>>> l = [1, 2, 3, 4, 5]
>>> print(a in l)
True
>>> print(b not in l)
True

7. Identity operator

Python The identity operators of are 2 individual

>>> a=123
>>> b=123
>>> c=456
>>> print(a is b)
True
>>> print(a is not c)
True

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved