
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Find size of a list in Python
A list is a collection data type in Python. The elements in a list are change able and there is no specific order associated with the elements. In this article we will see how to find the length of a list in Python. Which means we have to get the count of number of elements present in the list irrespective of whether they are duplicate or not.
Examples
In the below example we take a list named as "days". We first find the length of the list using len() function. And then we add few more elements and check the length again using append() function. Finally we remove some elements using remove() function and check the length again. Please note even though the elements are duplicate the remove() function will remove only e the elements at the end of the list
days = ["Mon","Tue","Wed"] print (len(days)) # Append some list elements days.append("Sun") days.append("Mon") print("Now the list is: ",days) print("Length after adding more elements: ",len(days)) # Remove some elements days.remove("Mon") print("Now the list is: ",days) print("Length after removing elements: ",len(days))
Output
Running the above code gives us the following result −
3 Now the list is: ['Mon', 'Tue', 'Wed', 'Sun', 'Mon'] Length after adding more elements: 5 Now the list is: ['Tue', 'Wed', 'Sun', 'Mon'] Length after removing elements: 4
- Related Articles
- Break a list into chunks of size N in Python
- How do we get size of a list in Python?
- How to get the size of a list in Python?
- How to find the size of a list in C#?
- How do we get the size of a list in Python?
- What is the maximum size of list in Python?
- How do I find the size of a Java list?
- Find average of a list in python?
- Program to find a sub-list of size at least 2 whose sum is multiple of k in Python
- Program to find size of Doubly Linked List in C++
- Python - Custom space size padding in Strings List
- Program to find size of each partition of a list where each letter appears at most one piece in Python
- Python program to Find the size of a Tuple
- Program to find size of sublist where product of minimum of A and size of A is maximized in Python
- Program to reverse linked list by groups of size k in Python
