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

Contenuti del Corso

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
Compito

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.

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 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
Compito

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.

Soluzione

Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Tutto è chiaro?

Come possiamo migliorarlo?

Grazie per i tuoi commenti!

Sezione 1. Capitolo 4
Switch to desktopCambia al desktop per esercitarti nel mondo realeContinua da dove ti trovi utilizzando una delle opzioni seguenti
Siamo spiacenti che qualcosa sia andato storto. Cosa è successo?
some-alt