Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

ลำดับความสำคัญของตัวดำเนินการ (Operator Precedence) ใน Python ที่ถูกต้องคืออะไร?

ตารางต่อไปนี้แสดงลำดับความสำคัญของตัวดำเนินการใน Python เริ่มจากสูงสุดไปสู่ต่ำสุด

** : Exponentiation (ยกกำลัง)
~ + - : Complement, unary plus and minus
* / % // : Multiply, divide, modulo และ floor division
+ - : Addition and subtraction
>> << : Right and left bitwise shift
& : Bitwise 'AND'
^ | : Bitwise exclusive 'OR' และ regular 'OR'
<= < > >= : Comparison operators
<> == != : Equality operators
= %= /= //= -= += *= **= : Assignment operators
is is not : Identity operators
in not in : Membership operators
not or and : Logical operators