Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
List Length | List
Python Data Structures
course content

Course Content

Python Data Structures

Python Data Structures

1. List
2. Dictionary
3. Tuple
4. Set

book
List Length

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
Task
test

Swipe to show code editor

Find out how many cities are in the travel_wishlist. Print the total number.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 4
toggle bottom row

book
List Length

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
Task
test

Swipe to show code editor

Find out how many cities are in the travel_wishlist. Print the total number.

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Section 1. Chapter 4
Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
We're sorry to hear that something went wrong. What happened?
some-alt