Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Arithmétique de Base et Priorité des Opérateurs | Nombres
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Types de Données en Python

bookArithmétique de Base et Priorité des Opérateurs

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

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 2

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Suggested prompts:

Can you explain more about operator precedence in Python?

What happens if I divide by zero in Python?

Can you give more examples of using parentheses to change evaluation order?

bookArithmétique de Base et Priorité des Opérateurs

Glissez pour afficher le menu

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

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 1. Chapitre 2
some-alt