Toán tử Python nói chung được sử dụng để thực hiện các thao tác trên các giá trị và biến. Đây là những ký hiệu tiêu chuẩn được sử dụng cho mục đích của các hoạt động logic và số học. Trong bài viết này, chúng ta sẽ xem xét các loại toán tử Python khác nhau.
- NGƯỜI ĐIỀU HÀNH. Là những ký hiệu đặc biệt. Ví dụ: + , * , /, v.v.
- TOÁN TỬ. Đó là giá trị mà toán tử được áp dụng
toán tử số học
Các toán tử số học được sử dụng để thực hiện các phép toán như cộng, trừ, nhân và chia
- Trong Trăn 3. x, kết quả của phép chia là dấu phẩy động trong khi ở Python 2. phép chia x của 2 số nguyên là một số nguyên và để thu được kết quả số nguyên trong Python 3. x thả nổi (// số nguyên) được sử dụng
QUYỀN ƯU TIÊN
- P – Dấu ngoặc đơn
- E – Luỹ thừa
- M – Phép nhân (Phép nhân và phép chia có cùng mức độ ưu tiên)
- D – Bộ phận
- A – Phép cộng (Phép cộng và phép trừ có cùng mức độ ưu tiên)
- S – Phép trừ
Toán tử mô đun giúp chúng tôi trích xuất các chữ số cuối cùng của một số. Ví dụ
- x % 10 -> mang lại chữ số cuối cùng
- x % 100 -> mang lại hai chữ số cuối
Thí dụ. Toán tử số học trong Python
Python3
False True False3
False True False4_______0_______5 False True False6
False True False7False True False5 False True False9
0 14 -11 14 2 400
0 14 -11 14 2 401
0 14 -11 14 2 402_______0_______5 False True False40 14 -11 14 2 405 False True False7
0 14 -11 14 2 400
0 14 -11 14 2 408
0 14 -11 14 2 409False True False5 False True False410 20 10 100 1024002 False True False7
0 14 -11 14 2 400
10 20 10 100 1024005
10 20 10 100 1024006False True False5 False True False410 20 10 100 1024009 False True False7
0 14 -11 14 2 400
is True if the operands are identical is not True if the operands are not identical 2
is True if the operands are identical is not True if the operands are not identical 3_______0_______5 False True False4is True if the operands are identical is not True if the operands are not identical 6 False True False7
0 14 -11 14 2 400
is True if the operands are identical is not True if the operands are not identical 9
True True0_______0_______5 False True False4_______29_______6is True if the operands are identical is not True if the operands are not identical 6 False True False7
0 14 -11 14 2 400
True True7
True True8False True False5 False True False4in True if value is found in the sequence not in True if value is not found in the sequence1 False True False7
0 14 -11 14 2 400
in True if value is found in the sequence not in True if value is not found in the sequence4
in True if value is found in the sequence not in True if value is not found in the sequence5False True False5 False True False410 20 10 100 102400910 20 10 100 1024009 False True False7
0 14 -11 14 2 400
x is NOT present in given list y is present in given list2
x is NOT present in given list y is present in given list3____59_______4
x is NOT present in given list y is present in given list3____59_______6
x is NOT present in given list y is present in given list3____59_______8
x is NOT present in given list y is present in given list3____67_______0
x is NOT present in given list y is present in given list3610 Hello! Welcome.2
x is NOT present in given list y is present in given list3610 Hello! Welcome.4
x is NOT present in given list y is present in given list3610 Hello! Welcome.6
Đầu ra13 5 36 2.25 2 1 6561
Ghi chú. Tham khảo Sự khác biệt giữa / và // để biết một số thông tin thú vị về hai toán tử này
Toán tử so sánh
So sánh các toán tử quan hệ so sánh các giá trị. Nó trả về Đúng hoặc Sai tùy theo điều kiện
OperatorDescriptionSyntax>Greater than: True if the left operand is greater than the rightx > y=Greater than or equal to True if the left operand is greater than or equal to the rightx >= yBitwise right shiftx>>=b a=a>>b