Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Changing value by index | 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
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
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 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
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 2
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