Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Iterating Through a List | 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
Iterating Through a List

Iterating through a list allows you to access and process each item individually. This is useful for performing actions on all items in your inventory.

A for loop can help you go through each item in the list.

123456
# Existing list inventory = ["cat", "dog", "chicken", "monkey"] # Iterate through the inventory for item in inventory: print("Item:", item)
copy

You can get a list of items in the inventory by writing ninja.inventory.values(). Now, instead of relying on the position on the map, you can iterate through the ninja's inventory and perform actions on each element in it.

py

ninja.py

copy

Remember that ninja.put_from_inventory() places the last item from the inventory.

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 3
py

ninja.py

toggle bottom row

book
Iterating Through a List

Iterating through a list allows you to access and process each item individually. This is useful for performing actions on all items in your inventory.

A for loop can help you go through each item in the list.

123456
# Existing list inventory = ["cat", "dog", "chicken", "monkey"] # Iterate through the inventory for item in inventory: print("Item:", item)
copy

You can get a list of items in the inventory by writing ninja.inventory.values(). Now, instead of relying on the position on the map, you can iterate through the ninja's inventory and perform actions on each element in it.

py

ninja.py

copy

Remember that ninja.put_from_inventory() places the last item from the inventory.

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 3
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