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

Conteúdo do Curso

Ninja Python

Ninja Python

1. Controles Básicos
2. Controles Avançados
3. Funções
4. Loops
5. Declarações If-Else
6. Desafios
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
Tarefa

Swipe to start coding

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 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
Tarefa

Swipe to start coding

Solução

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 7. Capítulo 2
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Sentimos muito que algo saiu errado. O que aconteceu?
some-alt