Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Changing value by index | Lists
Ninja de Python
course content

Contenido del Curso

Ninja de Python

Ninja de Python

1. Controles Básicos
2. Controles Avanzados
3. Funciones
4. Bucles
5. Sentencias If-Else
6. Desafíos
7. Lists

book
Changing value by index

In this chapter, we will learn how to change the value of a list element using its index in Python. To modify a specific element, access the list at the desired index and assign it a new value. For example:

123456789
# Existing list inventory = ["cat", "dog", "chicken", "monkey"] # Change the second element inventory[1] = "parrot" # inventory is now ["cat", "parrot", "chicken", "monkey"] print(inventory)
copy

You can also change an item in the ninja's inventory by index. To do this, you can pass the index to the ninja.pick_to_inventory(index) method.

py

ninja.py

copy
Tarea

Swipe to start coding

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 7. Capítulo 2
py

ninja.py

toggle bottom row

book
Changing value by index

In this chapter, we will learn how to change the value of a list element using its index in Python. To modify a specific element, access the list at the desired index and assign it a new value. For example:

123456789
# Existing list inventory = ["cat", "dog", "chicken", "monkey"] # Change the second element inventory[1] = "parrot" # inventory is now ["cat", "parrot", "chicken", "monkey"] print(inventory)
copy

You can also change an item in the ninja's inventory by index. To do this, you can pass the index to the ninja.pick_to_inventory(index) method.

py

ninja.py

copy
Tarea

Swipe to start coding

Solución

Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 7. Capítulo 2
Switch to desktopCambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Lamentamos que algo salió mal. ¿Qué pasó?
some-alt