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

Kurssisisältö

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
Tehtävä

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.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 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
Tehtävä

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.

Ratkaisu

Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Oliko kaikki selvää?

Miten voimme parantaa sitä?

Kiitos palautteestasi!

Osio 1. Luku 4
Switch to desktopVaihda työpöytään todellista harjoitusta vartenJatka siitä, missä olet käyttämällä jotakin alla olevista vaihtoehdoista
Pahoittelemme, että jotain meni pieleen. Mitä tapahtui?
some-alt