Hướng dẫn what does or mean in python - có nghĩa là gì trong python

Khác với tiêu chuẩn

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
8,
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
9,
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
0and
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
1 Các toán tử; Nhưng những điều này có nghĩa là gì (
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
2,
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
3,
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
4,
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
5)?

>>> 9+float(2) # addition
11.0
>>> 9-float(2) # subtraction
7.0
>>> 9*float(2) # multiplication
18.0
>>> 9/float(2) # division
4.5
>>>
>>> 9**float(2) # This looks like a square, (i.e. power 2) 
81.0
>>> 9**float(3) # So ** is equivalent to `math.pow(x,p)` ?
729.0

Làm thế nào về toán tử

>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
3?

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5

>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
4 Trong
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
8 trả về một mô đun còn lại bình thường, nhưng chỉ khi
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
9, tại sao lại như vậy?
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
4 làm gì?

>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0

Làm thế nào về toán tử

>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
5? nó làm gì?

>>> 9//float(2)
4.0
>>> 9//float(3)
3.0
>>> 9//float(4)
2.0
>>> 9//float(5)
1.0
>>> 9//float(6)
1.0
>>> 9//float(7)
1.0
>>> 9//float(8)
1.0
>>> 9//float(9)
1.0
>>> 9//float(1)
9.0
>>> 9//float(0.5)
18.0

Toán tử là các biểu tượng đặc biệt thực hiện các hoạt động trên các biến và giá trị. Ví dụ,

print(5 + 6)   # 11

Ở đây,

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
8 là một toán tử thêm hai số: 5 và 6.5 and 6.


Các loại người vận hành python

Dưới đây là danh sách các loại nhà khai thác python khác nhau mà chúng ta sẽ học trong hướng dẫn này.

  1. Toán tử số học
  2. Toán tử chuyển nhượng
  3. Toán tử so sánh
  4. Toán tử logic
  5. Các nhà khai thác bitwise
  6. Các nhà khai thác đặc biệt

1. Các toán tử số học Python

Các toán tử số học được sử dụng để thực hiện các hoạt động toán học như bổ sung, trừ, nhân, v.v.

sub = 10 - 5 # 5

Ở đây,

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
9 là một toán tử số học trừ hai giá trị hoặc biến.

Nhà điều hànhHoạt độngThí dụ
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
8
Phép cộng
>>> 9//float(2)
4.0
>>> 9//float(3)
3.0
>>> 9//float(4)
2.0
>>> 9//float(5)
1.0
>>> 9//float(6)
1.0
>>> 9//float(7)
1.0
>>> 9//float(8)
1.0
>>> 9//float(9)
1.0
>>> 9//float(1)
9.0
>>> 9//float(0.5)
18.0
5
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
9
Phép trừ
>>> 9//float(2)
4.0
>>> 9//float(3)
3.0
>>> 9//float(4)
2.0
>>> 9//float(5)
1.0
>>> 9//float(6)
1.0
>>> 9//float(7)
1.0
>>> 9//float(8)
1.0
>>> 9//float(9)
1.0
>>> 9//float(1)
9.0
>>> 9//float(0.5)
18.0
7
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
0
Phép nhân
>>> 9//float(2)
4.0
>>> 9//float(3)
3.0
>>> 9//float(4)
2.0
>>> 9//float(5)
1.0
>>> 9//float(6)
1.0
>>> 9//float(7)
1.0
>>> 9//float(8)
1.0
>>> 9//float(9)
1.0
>>> 9//float(1)
9.0
>>> 9//float(0.5)
18.0
9
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
1
Phân công
print(5 + 6)   # 11
1
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
4
Modulo
print(5 + 6)   # 11
3
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
2
Quyền lực
print(5 + 6)   # 11
5


Ví dụ 1: Người vận hành số học trong Python

a = 7
b = 2

# addition
print ('Sum: ', a + b)  

# subtraction
print ('Subtraction: ', a - b)   

# multiplication
print ('Multiplication: ', a * b)  

# division
print ('Division: ', a / b) 

# modulo
print ('Modulo: ', a % b)  

# a to the power b
print ('Power: ', a ** b)   

Đầu ra

Sum: 9
Subtraction: 5
Multiplication: 14
Division: 3.5
Modulo: 1
Power: 49

Trong ví dụ trên, chúng tôi đã sử dụng nhiều toán tử số học,

  • >>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
    11
    >>> 9^int(3)
    10
    >>> 9^int(4)
    13
    >>> 9^int(5)
    12
    >>> 9^int(6)
    15
    >>> 9^int(7)
    14
    >>> 9^int(8)
    1
    >>> 9^int(9)
    0
    >>> 9^int(10)
    3
    >>> 9^int(11)
    2
    >>> 9^int(12)
    5
    
    8 để thêm
    print(5 + 6)   # 11
    7 và
    print(5 + 6)   # 11
    8
  • >>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
    11
    >>> 9^int(3)
    10
    >>> 9^int(4)
    13
    >>> 9^int(5)
    12
    >>> 9^int(6)
    15
    >>> 9^int(7)
    14
    >>> 9^int(8)
    1
    >>> 9^int(9)
    0
    >>> 9^int(10)
    3
    >>> 9^int(11)
    2
    >>> 9^int(12)
    5
    
    9 để trừ
    print(5 + 6)   # 11
    8 từ
    print(5 + 6)   # 11
    7
  • >>> 9%float(2)
    1.0
    >>> 9%float(3)
    0.0
    >>> 9%float(4)
    1.0
    >>> 9%float(5)
    4.0
    >>> 9%float(6)
    3.0
    >>> 9%float(7)
    2.0
    >>> 9%float(8)
    1.0
    >>> 9%float(9)
    0.0
    >>> 9%float(10)
    9.0
    >>> 9%float(11)
    9.0
    >>> 9%float(12)
    9.0
    
    0 để nhân
    print(5 + 6)   # 11
    7 và
    print(5 + 6)   # 11
    8
  • >>> 9%float(2)
    1.0
    >>> 9%float(3)
    0.0
    >>> 9%float(4)
    1.0
    >>> 9%float(5)
    4.0
    >>> 9%float(6)
    3.0
    >>> 9%float(7)
    2.0
    >>> 9%float(8)
    1.0
    >>> 9%float(9)
    0.0
    >>> 9%float(10)
    9.0
    >>> 9%float(11)
    9.0
    >>> 9%float(12)
    9.0
    
    1 để chia
    print(5 + 6)   # 11
    7 cho
    print(5 + 6)   # 11
    8
  • >>> 9%float(2)
    1.0
    >>> 9%float(3)
    0.0
    >>> 9%float(4)
    1.0
    >>> 9%float(5)
    4.0
    >>> 9%float(6)
    3.0
    >>> 9%float(7)
    2.0
    >>> 9%float(8)
    1.0
    >>> 9%float(9)
    0.0
    >>> 9%float(10)
    9.0
    >>> 9%float(11)
    9.0
    >>> 9%float(12)
    9.0
    
    4 để có được phần còn lại
  • >>> 9%float(2)
    1.0
    >>> 9%float(3)
    0.0
    >>> 9%float(4)
    1.0
    >>> 9%float(5)
    4.0
    >>> 9%float(6)
    3.0
    >>> 9%float(7)
    2.0
    >>> 9%float(8)
    1.0
    >>> 9%float(9)
    0.0
    >>> 9%float(10)
    9.0
    >>> 9%float(11)
    9.0
    >>> 9%float(12)
    9.0
    
    2 để có được
    print(5 + 6)   # 11
    7 cho sức mạnh
    print(5 + 6)   # 11
    8

2. Các nhà khai thác phân công Python

Các toán tử gán được sử dụng để gán các giá trị cho các biến. Ví dụ,

# assign 5 to x 
var x = 5

Ở đây,

a = 7
b = 2

# addition
print ('Sum: ', a + b)  

# subtraction
print ('Subtraction: ', a - b)   

# multiplication
print ('Multiplication: ', a * b)  

# division
print ('Division: ', a / b) 

# modulo
print ('Modulo: ', a % b)  

# a to the power b
print ('Power: ', a ** b)   
2 là một toán tử gán gán
a = 7
b = 2

# addition
print ('Sum: ', a + b)  

# subtraction
print ('Subtraction: ', a - b)   

# multiplication
print ('Multiplication: ', a * b)  

# division
print ('Division: ', a / b) 

# modulo
print ('Modulo: ', a % b)  

# a to the power b
print ('Power: ', a ** b)   
3 cho
a = 7
b = 2

# addition
print ('Sum: ', a + b)  

# subtraction
print ('Subtraction: ', a - b)   

# multiplication
print ('Multiplication: ', a * b)  

# division
print ('Division: ', a / b) 

# modulo
print ('Modulo: ', a % b)  

# a to the power b
print ('Power: ', a ** b)   
4.

Dưới đây là danh sách các toán tử chuyển nhượng khác nhau có sẵn trong Python.

Nhà điều hànhHoạt độngThí dụ
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
8
Phép cộng
>>> 9//float(2)
4.0
>>> 9//float(3)
3.0
>>> 9//float(4)
2.0
>>> 9//float(5)
1.0
>>> 9//float(6)
1.0
>>> 9//float(7)
1.0
>>> 9//float(8)
1.0
>>> 9//float(9)
1.0
>>> 9//float(1)
9.0
>>> 9//float(0.5)
18.0
5
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
9
Phép trừ
>>> 9//float(2)
4.0
>>> 9//float(3)
3.0
>>> 9//float(4)
2.0
>>> 9//float(5)
1.0
>>> 9//float(6)
1.0
>>> 9//float(7)
1.0
>>> 9//float(8)
1.0
>>> 9//float(9)
1.0
>>> 9//float(1)
9.0
>>> 9//float(0.5)
18.0
7
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
0
Phép nhân
>>> 9//float(2)
4.0
>>> 9//float(3)
3.0
>>> 9//float(4)
2.0
>>> 9//float(5)
1.0
>>> 9//float(6)
1.0
>>> 9//float(7)
1.0
>>> 9//float(8)
1.0
>>> 9//float(9)
1.0
>>> 9//float(1)
9.0
>>> 9//float(0.5)
18.0
9
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
1
Phân công
print(5 + 6)   # 11
1
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
4
Modulo
print(5 + 6)   # 11
3
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
2
Quyền lực
print(5 + 6)   # 11
5
Ví dụ 1: Người vận hành số học trong PythonTrong ví dụ trên, chúng tôi đã sử dụng nhiều toán tử số học,
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
8 để thêm
print(5 + 6)   # 11
7 và
print(5 + 6)   # 11
8


>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u` 11 >>> 9^int(3) 10 >>> 9^int(4) 13 >>> 9^int(5) 12 >>> 9^int(6) 15 >>> 9^int(7) 14 >>> 9^int(8) 1 >>> 9^int(9) 0 >>> 9^int(10) 3 >>> 9^int(11) 2 >>> 9^int(12) 5 9 để trừ print(5 + 6) # 118 từ print(5 + 6) # 117

# assign 10 to a
a = 10

# assign 5 to b
b = 5 

# assign the sum of a and b to a
a += b      # a = a + b

print(a)

# Output: 15

>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
0 để nhân
print(5 + 6)   # 11
7 và
print(5 + 6)   # 11
8

>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
1 để chia
print(5 + 6)   # 11
7 cho
print(5 + 6)   # 11
8


>>> 9%float(2) 1.0 >>> 9%float(3) 0.0 >>> 9%float(4) 1.0 >>> 9%float(5) 4.0 >>> 9%float(6) 3.0 >>> 9%float(7) 2.0 >>> 9%float(8) 1.0 >>> 9%float(9) 0.0 >>> 9%float(10) 9.0 >>> 9%float(11) 9.0 >>> 9%float(12) 9.0 4 để có được phần còn lại

>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
2 để có được
print(5 + 6)   # 11
7 cho sức mạnh
print(5 + 6)   # 11
8

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
0

2. Các nhà khai thác phân công Python

Nhà điều hànhHoạt độngThí dụ
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
8
Phép cộng
>>> 9//float(2)
4.0
>>> 9//float(3)
3.0
>>> 9//float(4)
2.0
>>> 9//float(5)
1.0
>>> 9//float(6)
1.0
>>> 9//float(7)
1.0
>>> 9//float(8)
1.0
>>> 9//float(9)
1.0
>>> 9//float(1)
9.0
>>> 9//float(0.5)
18.0
5False
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
9
Phép trừ
>>> 9//float(2)
4.0
>>> 9//float(3)
3.0
>>> 9//float(4)
2.0
>>> 9//float(5)
1.0
>>> 9//float(6)
1.0
>>> 9//float(7)
1.0
>>> 9//float(8)
1.0
>>> 9//float(9)
1.0
>>> 9//float(1)
9.0
>>> 9//float(0.5)
18.0
7True
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
0
Phép nhân
>>> 9//float(2)
4.0
>>> 9//float(3)
3.0
>>> 9//float(4)
2.0
>>> 9//float(5)
1.0
>>> 9//float(6)
1.0
>>> 9//float(7)
1.0
>>> 9//float(8)
1.0
>>> 9//float(9)
1.0
>>> 9//float(1)
9.0
>>> 9//float(0.5)
18.0
9False
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
1
Phân công
print(5 + 6)   # 11
1True
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
4
Modulo
print(5 + 6)   # 11
3False
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
2
Quyền lực
print(5 + 6)   # 11
5True

Ví dụ 1: Người vận hành số học trong Python

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
1

Đầu ra

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
2

Trong ví dụ trên, chúng tôi đã sử dụng nhiều toán tử số học, Comparison operators are used in decision-making and loops. We'll discuss more of the comparison operator and decision-making in later tutorials.


>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u` 11 >>> 9^int(3) 10 >>> 9^int(4) 13 >>> 9^int(5) 12 >>> 9^int(6) 15 >>> 9^int(7) 14 >>> 9^int(8) 1 >>> 9^int(9) 0 >>> 9^int(10) 3 >>> 9^int(11) 2 >>> 9^int(12) 5 8 để thêm print(5 + 6) # 117 và print(5 + 6) # 118

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
9 để trừ
print(5 + 6)   # 11
8 từ
print(5 + 6)   # 11
7

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
3

>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
0 để nhân
print(5 + 6)   # 11
7 và
print(5 + 6)   # 11
8AND. Since both
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
03 and
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
04 are
# assign 5 to x 
var x = 5
3, the result is
# assign 5 to x 
var x = 5
3.

Nhà điều hànhThí dụHoạt động
Thí dụ
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
8and b
Phép cộng:
# assign 5 to x 
var x = 5
3 only if both the operands are
# assign 5 to x 
var x = 5
3
>>> 9//float(2)
4.0
>>> 9//float(3)
3.0
>>> 9//float(4)
2.0
>>> 9//float(5)
1.0
>>> 9//float(6)
1.0
>>> 9//float(7)
1.0
>>> 9//float(8)
1.0
>>> 9//float(9)
1.0
>>> 9//float(1)
9.0
>>> 9//float(0.5)
18.0
5
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
9or b
Phép trừ:
# assign 5 to x 
var x = 5
3 if at least one of the operands is
# assign 5 to x 
var x = 5
3
>>> 9//float(2)
4.0
>>> 9//float(3)
3.0
>>> 9//float(4)
2.0
>>> 9//float(5)
1.0
>>> 9//float(6)
1.0
>>> 9//float(7)
1.0
>>> 9//float(8)
1.0
>>> 9//float(9)
1.0
>>> 9//float(1)
9.0
>>> 9//float(0.5)
18.0
7
>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
0
a
Phép nhân:
# assign 5 to x 
var x = 5
3 if the operand is
# assign 5 to x 
var x = 5
4 and vice-versa.


>>> 9//float(2) 4.0 >>> 9//float(3) 3.0 >>> 9//float(4) 2.0 >>> 9//float(5) 1.0 >>> 9//float(6) 1.0 >>> 9//float(7) 1.0 >>> 9//float(8) 1.0 >>> 9//float(9) 1.0 >>> 9//float(1) 9.0 >>> 9//float(0.5) 18.0 9

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
4

>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
1: Here is the truth table for these logical operators.


Phân công

print(5 + 6)   # 11
1

>>> 9%float(2)
1.0
>>> 9%float(3)
0.0
>>> 9%float(4)
1.0
>>> 9%float(5)
4.0
>>> 9%float(6)
3.0
>>> 9%float(7)
2.0
>>> 9%float(8)
1.0
>>> 9%float(9)
0.0
>>> 9%float(10)
9.0
>>> 9%float(11)
9.0
>>> 9%float(12)
9.0
42 is
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
16 in binary and 7 is
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
17.

Modulo Let x = 10 (

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
18 in binary) and y = 4 (
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
19 in binary)

Nhà điều hànhNghĩaThí dụ
Không có giá trịBitwise vàX & Y = 0 (
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
20)
|Bitwise hoặcx | y = 14 (
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
21)
~Bit whole không~ x = -11 (
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
22)
^BitWise XORx ^ y = 14 (
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
21)
>>BitWise phải thay đổix >> 2 = 2 (
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
24)
Bitwise trái thay đổix 0010 1000)


6. Các nhà khai thác đặc biệt Python

Ngôn ngữ Python cung cấp một số loại toán tử đặc biệt như toán tử nhận dạng và nhà điều hành thành viên. Chúng được mô tả dưới đây với các ví dụ.identity operator and the membership operator. They are described below with examples.

Người vận hành danh tính

Trong Python,

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
25 và
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
26 được sử dụng để kiểm tra xem hai giá trị có được đặt trên cùng một phần của bộ nhớ không. Hai biến bằng nhau không ngụ ý rằng chúng giống hệt nhau.

Nhà điều hànhNghĩaThí dụ
Không có giá trịBitwise vàX & Y = 0 (
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
20)
|Bitwise hoặcx | y = 14 (
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
21)

~

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
5

Bit whole không

~ x = -11 (

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
22)


^

BitWise XOR

x ^ y = 14 (

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
21)

Nhà điều hànhNghĩaThí dụ
Không có giá trịBitwise vàfound in the sequence X & Y = 0 (
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
20)
|Bitwise hoặcnot found in the sequence x | y = 14 (
>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
21)

~

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
6

Bit whole không

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
7

~ x = -11 (

>>> 9^int(2) # What is `^` in `x^u` , it only allows `int` for `u`
11
>>> 9^int(3)
10
>>> 9^int(4)
13
>>> 9^int(5)
12
>>> 9^int(6)
15
>>> 9^int(7)
14
>>> 9^int(8)
1
>>> 9^int(9)
0
>>> 9^int(10)
3
>>> 9^int(11)
2
>>> 9^int(12)
5
22)

^

BitWise XOR

Trong bài viết này, chúng tôi đã tìm hiểu về các toán tử logic và tương đương với && (logic và) và ||(logic-or) trong một câu chuyện if.logical-or) in an if-statement.

Làm gì Ít hơn hoặc bằng.. Ý nghĩa của toán tử ||?

Logic hoặc toán tử: ||Logical hoặc toán tử (||) trả về giá trị boolean true nếu một hoặc cả hai toán hạng là đúng và trả về sai.returns the boolean value true if either or both operands is true and returns false otherwise.