Ibuprofeno.py馃拪| #150: Explica este c贸digo Python

Cristian Fernando - Jul 25 - - Dev Community

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].

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player