Hướng dẫn assignment operators in python 3 - toán tử gán trong python 3
Giả sử biến A giữ giá trị 10 và biến B giữ giá trị 20, sau đó -a holds the value 10 and variable b holds the value 20, then − Show
Thí dụGiả sử biến A giữ giá trị 10 và biến B giữ giá trị 20, sau đó -a holds the value 10 and variable b holds the value 20, then − #!/usr/bin/python3 a = 21 b = 10 c = 0 c = a + b print ("Line 1 - Value of c is ", c) c += a print ("Line 2 - Value of c is ", c ) c *= a print ("Line 3 - Value of c is ", c ) c /= a print ("Line 4 - Value of c is ", c ) c = 2 c %= a print ("Line 5 - Value of c is ", c) c **= a print ("Line 6 - Value of c is ", c) c //= a print ("Line 7 - Value of c is ", c) =Gán các giá trị từ các toán hạng bên phải sang bên trái bên trái Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 99864 python_basic_operators.htm 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ụ,
Ở đây, Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 998646 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 pythonDướ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. Các toán tử số học PythonCá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.
Ở đây, Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 998647 là một toán tử số học trừ hai giá trị hoặc biến.
Ví dụ 1: Người vận hành số học trong Python
Đầ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,
2. Các nhà khai thác phân công PythonCác toán tử gán được sử dụng để gán các giá trị cho các biến. Ví dụ,
Ở đây, 6 là một toán tử gán gán 7 cho 8.Dưới đây là danh sách các toán tử chuyển nhượng khác nhau có sẵn trong Python.
Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 99864 6 để thêm sub = 10 - 5 # 51 và sub = 10 - 5 # 52
Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 998647 để trừ 2 từ 1 2 với nhân 1 và 2print(5 + 6) # 114 để chia sub = 10 - 5 # 51 cho sub = 10 - 5 # 52 6 để có được phần còn lại
8 để có được 1 cho sức mạnh 2
Ví dụ 1: Người vận hành số học trong Python
Đầu ra Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 998640 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. Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 99864 6 để thêm sub = 10 - 5 # 51 và sub = 10 - 5 # 52Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 998647 để trừ 2 từ 1Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 998641 2 với nhân 1 và 2AND. Since both 7 and 8 are 7, the result is 7.
print(5 + 6) # 113Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 998642
Phân công 5 62 is Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 9986400 in binary and 7 is Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 9986401. Modulo Let x = 10 ( Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 9986402 in binary) and y = 4 ( Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 9986403 in binary)
print(5 + 6) # 119Ví dụ 1: Người vận hành số học trong Pythonidentity operator and the membership operator. They are described below with examples. Đầu raTrong ví dụ trên, chúng tôi đã sử dụng nhiều toán tử số học,
Ví dụ 4: Người vận hành danh tính trong PythonLine 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 998643 Ở đây, chúng ta thấy rằng X1 và Y1 là số nguyên của cùng một giá trị, vì vậy chúng bằng nhau cũng như giống hệt nhau. Tương tự là trường hợp với x2 và y2 (chuỗi). Nhưng x3 và y3 là danh sách. Họ bằng nhau nhưng không giống nhau. Đó là bởi vì trình thông dịch định vị chúng riêng biệt trong bộ nhớ mặc dù chúng bằng nhau. Các nhà khai thác thành viênTrong Python, Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 9986417 và Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 9986418 là các nhà khai thác thành viên. Chúng được sử dụng để kiểm tra xem một giá trị hoặc biến được tìm thấy trong một chuỗi (chuỗi, danh sách, tuple, bộ và từ điển). Trong một từ điển, chúng ta chỉ có thể kiểm tra sự hiện diện của khóa, không phải giá trị.
Ví dụ 5: Các nhà khai thác thành viên trong PythonLine 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 998644 Đầu ra Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 998645 Ở đây, Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 9986425 nằm trong x nhưng Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 9986426 không có trong X (hãy nhớ, Python là trường hợp nhạy cảm). Tương tự, Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 9986427 là chìa khóa và Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 9986428 là giá trị trong từ điển y. Do đó, Line 1 - Value of c is 31 Line 2 - Value of c is 52 Line 3 - Value of c is 1092 Line 4 - Value of c is 52.0 Line 5 - Value of c is 2 Line 6 - Value of c is 2097152 Line 7 - Value of c is 9986429 trả về 8.
Các toán tử chuyển nhượng trong Python là gì?Sau đây là các loại toán tử phân công khác nhau trong Python:.. Toán tử gán đơn giản (=). Thêm và toán tử bằng ( +=). Trừ và toán tử bằng ( -=). Dấu hoa thị và toán tử bằng nhau ( *=). Chia và toán tử bằng ( /=). Mô đun và toán tử bằng nhau ( %=). Phân chia kép và toán tử bằng nhau (// =). 3 toán tử trong Python là gì?Python chia các toán tử trong các nhóm sau: toán tử số học. Toán tử chuyển nhượng. Toán tử so sánh.Arithmetic operators. Assignment operators. Comparison operators.
6 toán tử gán là gì?Các loại toán tử chuyển nhượng trong C.. Bài tập cơ bản (=). Bài tập trừ ( -=). Bổ sung gán ( +=). Phân chia phân công ( /=). Bài tập nhân ( *=). gán modulo ( %=). BitWise XOR gán ( ^=). bitwise hoặc gán (| =). Toán tử gán và loại của nó là gì?Có hai loại hoạt động gán: gán đơn giản, trong đó giá trị của toán hạng thứ hai được lưu trữ trong đối tượng được chỉ định bởi toán hạng đầu tiên.Việc gán hợp chất, trong đó hoạt động số học, dịch chuyển hoặc bitwise được thực hiện trước khi lưu trữ kết quả.
Các toán tử chuyển nhượng là gì?Toán tử gán = gán giá trị của toán hạng bên phải của nó cho một biến, thuộc tính hoặc phần tử chỉ mục được đưa ra bởi toán hạng bên trái của nó.Kết quả của một biểu thức gán là giá trị được gán cho toán hạng bên trái.assigns the value of its right-hand operand to a variable, a property, or an indexer element given by its left-hand operand. The result of an assignment expression is the value assigned to the left-hand operand. |