ลำดับความสำคัญของตัวดำเนินการใน Python Operators Precedence
ในตารางจะแสดง operators ทั้งหมดของ ไพทอน ลำดับความสำคัญจากมากไปน้อย
Operator | Description |
---|---|
** | ยกกำลัง |
~ + - | Ccomplement, unary plus and minus |
* / % // | คูณ, หาร, modulo and floor division |
+ - | บวก, ลบ |
>> << | Right and left bitwise shift |
& | Bitwise 'AND' |
^ | | Bitwise exclusive `OR' and regular `OR' |
<= < > >= | Comparison operators |
<> == != | Equality operators |
= %= /= //= -= += *= **= | Assignment operators |
is is not | Identity operators |
in not in | Membership operators |
not or and | Logical operators |
นอกจากในตารางแล้วยังมีตัวดำเนินการที่มีลำดับความคำคัญสูงสุดคือ "(...)"
ตัวอย่าง
a=2
b=3
c=4
print(a**b+c)
มีค่าเท่ากับ
print (2*2*2+4);
จะได้ผลลัพท์ เป็น 12