- If multiple operators present then which operator will be evaluated first is decided by operator precedence.
Example
Python
print(3+10*2)
print((3+10)*2)
Output
PowerShell
23
26
- The following list describes operator precedence in Python.
- () ⇒ Parenthesis
- ** ⇒ Exponential operator
- ~, – ⇒ Bitwise complement operator, unary minus operator
- *, /, %, // ⇒ multiplication, division, modulo, floor division
- +, – ⇒ addition, subtraction
- <<, >> ⇒ Left and Right Shift
- & ⇒ bitwise And
- ^ ⇒ Bitwise XOR
- | ⇒ Bitwise OR
- >, >=, <, <=, ==, != ⇒ Relational or Comparison operators
- =, +=, -=, =… ⇒ Assignment operators
- is, is not ⇒ Identity Operators
- in , not in ⇒ Membership operators
- not ⇒ Logical not
- and ⇒ Logical and
- or ⇒ Logical or
Example
Python
num1 = 30
num2 = 20
num3 = 10
num4 = 5
print((num1+num2)*num3/num4)
print((num1+num2)*(num3/num4))
print(num1+(num2*num3)/num4)
Output
PowerShell
100.0
100.0
70.0
Ungraded Questions
Get ready for an exhilarating evaluation of your understanding! Brace yourself as we dive into the upcoming assessment. Your active participation is key, so make sure to attend and demonstrate your knowledge. Let’s embark on this exciting learning journey together!