howtouselinux
Feb 4, 2022

Get list length in Python 3 Examples

Get list length with len() function

list = [10, 20, 30]

n = len(list)

print(“The length of list is: “, n)

Get list length with for loop

list = [‘Python’,’Java’,’Kotlin’,’Machine Learning’,’Keras’]

size = 0

print(“Length of the input string:”)

for x in list:

size+=1

print(size)

Get list length with len() function for nested list

nestedList = [‘Krishna’, 20,’John’, [20, 40, 50, 65, 22], ‘Yung’, 11.98]

print(“Original List = “, nestedList)

print(“Length of a Nested List = “, len(nestedList[3]))

​how to get the list length in python​

howtouselinux
howtouselinux

Written by howtouselinux

subscribe, please. We bring real-world experience, the latest trends, and DevOps tips here. contact me: https://forms.gle/dfhQfmTMFhtLAoaa9

No responses yet