In this tutorial, learn how to find size of list item using Python. The short answer is: Use the Python len() function to get the length of list items. The elements of the list variable are the items enclosed within the single or double quotes.
A list variable may contain elements same as the element we find in an array in other programming languages like Java. You may also like to read how to create variables in Python to create other types of variables.
How to Find Size of List Items in python
To find the length of the list variable in Python, you have to use the
len() function. Inside the len(), you have to pass the list variable as the argument of it.
Now, if you print the combination as given in the example below. You will get the exact number of the list items available in the list variable. It counts the string as well as the integer and float items of the list variable of Python.
myList = ['Dhammo', 'Bahubali', 20, 'Katappa', 24.5, 'Suresh'];
The above example gives 6 as the output of the len() function. There are six elements inside the list variable. However, you can add more items to the list in Python. After that, you have to use the Python print statement to find the size of list items and print the length in the output.
You may also like to read
- How to loop over Python list variable
- Find Length Of Tuple Or Get Items Size Using Python
- How To Count String Characters Length Using JQuery
Hope, you like this tutorial of how to get the length and find size of list items in Python. If you have any query regarding the tutorial, please comment below.
- jQuery-az Tutorial on len() function for getting the length of a list Python
- Geeksforgeeks Tutorial on How to Find length of a list in Python
- Stackoverflow Discussion on How do I get the number of elements in a list?
Also tell me, which method you are using to get the length of the list items in Python.