Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Iterating Through a List | Lists
Python Ninja
course content

Kursinhalt

Python Ninja

Python Ninja

1. Grundlegende Steuerungen
2. Erweiterte Steuerungen
3. Funktionen
4. Schleifen
5. If-Else Anweisungen
6. Herausforderungen
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.

Aufgabe

Swipe to start coding

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 7. Kapitel 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.

Aufgabe

Swipe to start coding

Lösung

Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 7. Kapitel 3
Switch to desktopWechseln Sie zum Desktop, um in der realen Welt zu übenFahren Sie dort fort, wo Sie sind, indem Sie eine der folgenden Optionen verwenden
Wir sind enttäuscht, dass etwas schief gelaufen ist. Was ist passiert?
some-alt