Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Python List Length: Measuring and Managing List Size | Mastering Python Lists
Python Data Structures
course content

Kursinnhold

Python Data Structures

Python Data Structures

2. Mastering Python Dictionaries
3. Mastering Python Tuples
4. Mastering Python Sets

book
Python List Length: Measuring and Managing List Size

When working with large or complex lists, knowing how many elements they contain is often useful. Python provides the len() function, which returns the total number of items in a list.

Note

A nested list is considered a single item. The len() function doesn't count the individual items inside a nested list as separate items of the main list.

12345
cities_list = ["Tokyo", "New York", "Sydney", "Berlin", ["Paris", "France"]] list_length = len(cities_list) print(list_length)
copy
Oppgave

Swipe to start coding

Find out how many cities are in the travel_wishlist.

  • Assign the value of the length of the travel_wishlist list to the variable list_length.
  • Use the len function to find a length.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 4
toggle bottom row

book
Python List Length: Measuring and Managing List Size

When working with large or complex lists, knowing how many elements they contain is often useful. Python provides the len() function, which returns the total number of items in a list.

Note

A nested list is considered a single item. The len() function doesn't count the individual items inside a nested list as separate items of the main list.

12345
cities_list = ["Tokyo", "New York", "Sydney", "Berlin", ["Paris", "France"]] list_length = len(cities_list) print(list_length)
copy
Oppgave

Swipe to start coding

Find out how many cities are in the travel_wishlist.

  • Assign the value of the length of the travel_wishlist list to the variable list_length.
  • Use the len function to find a length.

Løsning

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 4
Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Vi beklager at noe gikk galt. Hva skjedde?
some-alt