Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen Creating Lists in Python: Declaring and Initializing Lists | Liste
Python-Datenstrukturen
Abschnitt 1. Kapitel 1
single

single

Creating Lists in Python: Declaring and Initializing Lists

Swipe um das Menü anzuzeigen

Prerequisites
Voraussetzungen

Data structures are essential tools for organizing data, allowing for more efficient access depending on the specific needs of a program. They form the foundation of any programming language and are central to building functional and effective programs. In Python, the main data structures include lists, tuples, dictionaries, and sets, each offering unique features and capabilities.

Understanding Python Lists

Python lists are ordered collections that are mutable and may contain elements of any data type. In Python, a list is created by putting the items inside square brackets. Here's an example:

1234
# City name, population, area, is a major metropolitan city_info = ["New York", 8419600, 468.9, True] print(city_info)

As shown, a list can contain a mix of different items or even be completely empty. Take a look at the following example:

cities = []

To initialize an empty list, simply assign empty square brackets to a variable.

Aufgabe

Wischen, um mit dem Codieren zu beginnen

Initialize a list named travel_wishlist.

  • The list should contain 3 elements: "London", "Tokyo", "Berlin" (the order doesn’t matter).

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 1. Kapitel 1
single

single

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

some-alt