Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Aritmética Básica y Precedencia de Operadores | Números
Tipos de Datos en Python

bookAritmética Básica y Precedencia de Operadores

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

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 2

Pregunte a AI

expand

Pregunte a AI

ChatGPT

Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla

bookAritmética Básica y Precedencia de Operadores

Desliza para mostrar el menú

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

¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 2
some-alt