Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer Basisrekenen en Operatorprioriteit | Getallen
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Gegevenstypen in Python

bookBasisrekenen en Operatorprioriteit

You'll use arithmetic operators constantly in Python. Consider the most common ones and how precedence determines evaluation order.

Main Operations

12345678
a = 10 b = 3 print(a + b) # Addition print(a - b) # Subtraction print(a * b) # Multiplication print(a / b) # Division print(a ** b) # Exponentiation
copy

Operator Precedence

When multiple operators appear, Python evaluates them in this order (highest → lowest among arithmetic):

  1. **;
  2. Unary + and - (sign);
  3. *, /;
  4. +, -.

Parentheses always win and make intent explicit. Exponentiation ** is right-associative.

123456789
print(2 + 3 * 4) # 14 (multiplication before addition) print((2 + 3) * 4) # 20 (parentheses change the order) # Exponentiation binds tighter than unary minus print(-3 ** 2) # -9 (equivalent to -(3 ** 2)) print((-3) ** 2) # 9 # Right-associative exponentiation print(2 ** 3 ** 2) # 512 (2 ** (3 ** 2))
copy
Note
Note
  • Prefer parentheses in anything nontrivial, readability > cleverness.
  • Remember / always yields a float (even if divisible).

1. What value will this code output?

2. Which expression evaluates to 64?

3. What value will this code output?

question mark

What value will this code output?

Select the correct answer

question mark

Which expression evaluates to 64?

Select the correct answer

question mark

What value will this code output?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 2

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

bookBasisrekenen en Operatorprioriteit

Veeg om het menu te tonen

You'll use arithmetic operators constantly in Python. Consider the most common ones and how precedence determines evaluation order.

Main Operations

12345678
a = 10 b = 3 print(a + b) # Addition print(a - b) # Subtraction print(a * b) # Multiplication print(a / b) # Division print(a ** b) # Exponentiation
copy

Operator Precedence

When multiple operators appear, Python evaluates them in this order (highest → lowest among arithmetic):

  1. **;
  2. Unary + and - (sign);
  3. *, /;
  4. +, -.

Parentheses always win and make intent explicit. Exponentiation ** is right-associative.

123456789
print(2 + 3 * 4) # 14 (multiplication before addition) print((2 + 3) * 4) # 20 (parentheses change the order) # Exponentiation binds tighter than unary minus print(-3 ** 2) # -9 (equivalent to -(3 ** 2)) print((-3) ** 2) # 9 # Right-associative exponentiation print(2 ** 3 ** 2) # 512 (2 ** (3 ** 2))
copy
Note
Note
  • Prefer parentheses in anything nontrivial, readability > cleverness.
  • Remember / always yields a float (even if divisible).

1. What value will this code output?

2. Which expression evaluates to 64?

3. What value will this code output?

question mark

What value will this code output?

Select the correct answer

question mark

Which expression evaluates to 64?

Select the correct answer

question mark

What value will this code output?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 2
some-alt