How To Get Length and Size Of The List In Python?

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/get-length-size-list-python/
PINTEREST
PINTEREST
INSTAGRAM

Python is very expressive language which provides different structures to easy developers work. List is one of the most popular data structure provided by the python. In a regular work flow we add and remove elements into and from list. But in this floating situations we need to get the length of the list. How can we get the length or size of the list? In this tutorial we will look different ways to get a list length

Using Built-in Len Function

As we stated before len is a builtin function provided python by default. We can use this function just providing the list as an argument like below.

As we can the the size of the pb list is 3.

Get Multi Dimension List Length

In previous we have looked the length of a single dimension list. But in real world situations there will be multi-dimension lists. We can also get the length of this list single dimension length just providing the index of the related sub list like below. In this example we want to get the length of the first sub array.

We provide the sublist element index as  which is ['ismail','elif'] and get the length of this sub list as  2

 

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/get-length-size-list-python/
PINTEREST
PINTEREST
INSTAGRAM

LEARN MORE  Python For Loop Tutorial With Examples and Range/Xrange Functions

Leave a Reply

Your email address will not be published.