Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Python Lists | Other Data Types in Python
Introduction to Python(ihor)

bookPython Lists

To create a list, place comma-separated values inside square brackets [], or convert an iterable (like a string, set, or tuple) using list(). For example, you can create a list with details about the USA (country name, land area, and population).

12345
# Creating list information = ["USA", 9629091, 331002651] # Printing list print(information)
copy

Accessing list elements is similar to accessing characters in a string. You can do this using indexing and slicing.

To retrieve the land area and population from US_Info, target the second (index 1) and third (index 2) items. Use slicing with a colon : to specify the start and end positions. The upper limit of a slice is excluded, so use [1:3] to retrieve these two elements.

12345
# Getting area and population information = ["USA", 9629091, 331002651] # Printing list print(information[1:3])
copy
question mark

Which type of brackets is used to define a list?

Select the correct answer

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 4. Kapitel 1

Spørg AI

expand

Spørg AI

ChatGPT

Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat

Suggested prompts:

Spørg mig spørgsmål om dette emne

Opsummér dette kapitel

Vis virkelige eksempler

Awesome!

Completion rate improved to 1.67

bookPython Lists

Stryg for at vise menuen

To create a list, place comma-separated values inside square brackets [], or convert an iterable (like a string, set, or tuple) using list(). For example, you can create a list with details about the USA (country name, land area, and population).

12345
# Creating list information = ["USA", 9629091, 331002651] # Printing list print(information)
copy

Accessing list elements is similar to accessing characters in a string. You can do this using indexing and slicing.

To retrieve the land area and population from US_Info, target the second (index 1) and third (index 2) items. Use slicing with a colon : to specify the start and end positions. The upper limit of a slice is excluded, so use [1:3] to retrieve these two elements.

12345
# Getting area and population information = ["USA", 9629091, 331002651] # Printing list print(information[1:3])
copy
question mark

Which type of brackets is used to define a list?

Select the correct answer

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 4. Kapitel 1
some-alt