Working With Lists
Sveip for å vise menyen
In this chapter, we will learn about lists — one of the most useful data structures in Python.
A list is a collection of items. For example, you can store a list of colours or numbers.
Lists are defined using square brackets. You can also sort them using the sorted() function, or apply a lambda to transform elements — lambda x: x * 2 — which is an anonymous function. We'll cover lambdas properly in the next section.
Here is how to create a list:
123fruits = ['apple', 'banana', 'cherry'] print(fruits[0]) print('The list has', len(fruits), 'items')
Decorators are a powerful way to modify function behaviour at definition time.
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 2. Kapittel 1
Spør AI
Spør AI
Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår
Seksjon 2. Kapittel 1