The following table lists all operators from highest precedence to lowest.
|**||Exponentiation (raise to the power)|
|~ + –||Complement, unary plus and minus (method names for the last two are +@ and -@)|
|* / % //||Multiply, divide, modulo and floor division|
|+ –||Addition and subtraction|
|>> <<||Right and left bitwise shift|
|^ |||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|
Be aware that operator precedence affects how an expression is evaluated:
a = 5 + 2 * 3 is equal 11 not 21 as Python will do multiplication first
2*3 and addition lat
5 + 6 as multiplication has highest precedence. If you want for addition to be evaluate first you must use parentheses to enforce a different precendence, for example
a = (5 + 2) * 3.
Please like and share to spread the knowledge in the community.
If you want to chat with me please use Twitter: @AngrySysOps
Visit my FB page: https://www.facebook.com/AngrySysOps
Read my blog: https://angrysysops.com
Subscribe to my channel : https://www.youtube.com/channel/UCRTcKGl0neismSRpDMK_M4A