DEV Community

Cover image for Ibuprofeno.py💊| #75: Explica este código Python
Cristian Fernando
Cristian Fernando

Posted on

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

Explica este código Python

Dificultad: Intermedio

test = list(range(11))
test[:6] = [10, 10, 10, 10, 10]
print(test)
Enter fullscreen mode Exit fullscreen mode

👉 A. [10, 10, 10, 10, 10]
👉 B. [1, 2, 3, 4, 5, 6, 10, 10, 10, 10, 10]
👉 C. [10, 10, 10, 10, 10, 6, 7, 8, 9, 10]
👉 D. [0, 1, 2, 3, 4, 5]


Respuesta:

👉 C. [10, 10, 10, 10, 10, 6, 7, 8, 9, 10]

Vamos línea por línea:

  • test = list(range(11)):
    Creamos en la variable test una lista de números, del 0 al 10. Tendríamos: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

  • test[:6] = [10, 10, 10, 10, 10]:
    De la posición 0 a la posición 5 agregamos el arreglo [10, 10, 10, 10, 10]

  • print(test):
    Imprimimos el resultado: [10, 10, 10, 10, 10, 6, 7, 8, 9, 10]

Top comments (0)