Python List Length - How to find a list of length and print list

In this section we learn about the python print list of length and size. Here we describe how to print list of length and python. Minimum and maximum size length of list in python. The python programming language developer does not fix the size of list length. When programmer make high size and length of  code their is chance to  crash ram in this case programmer use to (yeild ,nxt, iter ) function in python. The basic description of list is multiple value element string and int is one variable. In this section we describe the method of list. Explain the example of size length and list of python with beginner and advance python project.

python list length

Python List Length

Find the length of list in python programming use len() method. len() method is a built in function len() method helps to show the total length of int string including all data types like list set tuples dictionary

python list is the one of the types of data types. Data types are set, dictionary, tuples and list. Python list is allow to make value double and python list is access able to change the value. List is mostly use to save multiple data if int and string. The python list of length is find by using len() function In some case like Object Oriented Programming programmer mostly use __len__() to find the total length of string in python list. __len__ () it is also called a dunder method in python.

Method of List in Python 

The different types of method in list. Such types of method mainly use are as follow add()method, remove()method index()method, insert()method, pop()method, append()method, reverse()method, sort()method, clear()method and copy()method. This type of list method is use to add remove clear copy short reverse. Now we see the some basic example of method of list.

a = [1,2,3,4,5]
print(a)
a[0] = 34
print(a)

Here first make a list with list name a . a[0] is excess the first value of list of a. Excess the first value of a and change the value of 34

INOUTPUT 

[1, 2, 3, 4, 5]
[34, 2, 3, 4, 5] 

See her the output of a is change first a is 1 second a is 34 because excess the a and change value.

Example:2

s1 = [1,2,5,4,3,2,5,78,45,9]print(s1)
s1.sort()
#codebugfree
print(s1)
s1.reverse()
print(s1)
s1.append(7)
print(s1)
s1.append(45)
print(s1)
s1.insert(3, 70)
print(s1)
s1.pop(3)
print(s1)
s1.remove(5)
print(s1)

Here describe the all method of list and it is example of all method of list

INOUTPUT

[1, 2, 5, 4, 3, 2, 5, 78, 45, 9]
[1, 2, 2, 3, 4, 5, 5, 9, 45, 78]   
[78, 45, 9, 5, 5, 4, 3, 2, 2, 1]   
[78, 45, 9, 5, 5, 4, 3, 2, 2, 1, 7]
[78, 45, 9, 5, 5, 4, 3, 2, 2, 1, 7, 45]
[78, 45, 9, 70, 5, 5, 4, 3, 2, 2, 1, 7, 45]
[78, 45, 9, 5, 5, 4, 3, 2, 2, 1, 7, 45]
[78, 45, 9, 5, 4, 3, 2, 2, 1, 7, 45]

How to find list of length

We can find the list of length is using built in function. That is len() and __len__(). First we see the basic example to see the list of the length. 

Example:1

my_1list = [1234,64,3234,5678,234,1847321,4872315,857,1243,87789]#first list
print("the total length of first list",len(my_1list))
my_2list = ["please","follow","our","website"]#second list
#codebugfree
print("the total length of second list",len(my_2list))
my_3list = [1,"code",56,"87","kukuri","19",7]#third list
print("the total length of third list",len(my_3list))

First we create three list and gives the element or value use the len function with print.

INOUTPUT

the total length of first list 10
the total length of second list 4
the total length of third list 7

Example: 2

class Length_of_list():#class
    def __init__(self,):#init construction
        self.best_friend_name = "python","c","c++","java","R","kotlin" # variable

    def __len__(self):
        print(f"the total best friends of code bug free is {self.best_friend_name.__len__()}") #finding the length of friend
    
codebugfree_friend = Length_of_list()#object
codebugfree_friend.__len__()

In this example here is use a oops concept if you don't know than you does not know this example first you know the basic oops concepts. Making class with init constructor and make the variable with friend name and pass the friend name. __len__ is now calculate the total friend. At last making object and print the length of codebugfree friend.

INOUTPUT

the total best friends is 6

Post a Comment

0 Comments