Showing posts with label python list datatype. Show all posts
Showing posts with label python list datatype. Show all posts

How to check the length of the elements in python list object

# How to check the length of the elements in python list object using len() function

Length of a List

In order to find the number of items present in a list, we can use the len() function.

Ex:

list=[20,33,44,55,"ramesh","rani",56.88]

print(len(list))


# print secod index to upto end of the list values using len() function
Ex:

list=[20,33,44,55,"ramesh","rani",56.88]
for x in range(2,len(list)):
    print(list[x])

Iterating a List Object Values in Python

 # Iterating a List Object Values in Python :

# The objects in the list can be iterated over one by one, by using a for loop

Ex:

courses=["python","Django","Flask","Pyspark"]

for x in courses:

    print(x)


# Iterate along with an index number:

Ex:

mylist = [5, 8, 'ram', 7.50, 'ravi']

for i in range(2, len(mylist)):

     print(mylist[i])


Python list datatype

 python list datatype:

list is a flexible, versatile, powerful, and popular built-in data type.

store multiple values in single variable and different datatypes


we can use list datatype in two ways

one is direct list variable

ex:

mylist=[10,20,40,50,90]

print(mylist)


second one is

list() constructor its class name

ex:

mylist=list([10,30,40,60,90])

print(mylist)


list heterogeneous items
heterogeneous means group of datatypes
Ex:
mylist = [10, 20, 'ram', 12.50, 'praveen', 25, 50]
print(mylist)

Latest Post

Don’t Sweat It – Chill with Crompton Air Cooler Deals

 ðŸŒž Don’t Sweat It – Chill with Crompton Air Cooler Deals  More Details : https://www.amazon.in/s?k=laptops+under+70000&crid=29QIFPXQYB3...