DEV Community

Cristian Fernando
Cristian Fernando

Posted on • Edited on

1

Ibuprofeno.py💊| #32: Explica este código Python

Explica este código Python

Dificultad: Intermedio

## Reto #32
x = (10, 20)
def fn(entrada):
    entrada.append(30)
    return entrada

fn(x)
print(x) # 🤔
Enter fullscreen mode Exit fullscreen mode
  • A. TypeError
  • B. AttributeError
  • C. (10, 20, 30)
  • D. (10, 20)

Respuesta en el primer comentario.

Respuesta:

  • B. AttributeError

Este reto es un poco trampa.
Pareciera que queremos demostrar si una tupla se pasa por valor o por referencia a una función en Python, pero basta con saber que una tupla es inmutable para saber que debe ser pasada si o si por valor.

Por su característica de inmutabilidad las tuplas no cuentan con un método append() como las listas, así que no es necesario leer todo el código del reto, basta con saber la teoría.

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay