DEV Community

Cristian Fernando
Cristian Fernando

Posted on

1

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

Explica este código Python

Dificultad: Fácil

my_list = [1, 2, 3]
my_list.append([4,5])
print(my_list)
Enter fullscreen mode Exit fullscreen mode
  • A. [1, 2, 3, 4, 5]
  • B. [1, 2, 3, [4, 5]]
  • C. [1, 2, 3, (4, 5)]
  • D. [1, 2, 3, "45"]

Respuesta:

👉 B. [1, 2, 3, [4, 5]]

El método append() sirve para agregar elementos al final de una lista, ojo, elementos sueltos; en nuestro ejemplo intentamos agregar otra lista.

Es posible hacer esto con append() pero el resultado no sera esperado por que tendremos una lista anidada.

En este caso, podríamos usar el método extend() que nos regresará [1, 2, 3, 4, 5].

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more