How to Use len() Function in Python !

The len() function returns the number of items in an object. When the object is a string, the len() function returns the number of characters in the string. and len() is a built-in function in python. use the len() to get the length of the given string, array, list, tuple, dictionary.etc

Use in String =

test = len(input(“what is your name? “))
print(“The Total lenth of the String is:”, test)

Output:-

Use in list =

test = len([“apple”, “mango”,”banana”])
print(“The Total lenth of the list is:”, test)

Output:-

Use in Dictionary =

test = len(
{
“key”:”Value”,
“India”:”Delhi”,
}
)

print(“The Total lenth of the Dict is:”, test)

Output:-

Use in Tuple =

test = len((‘april’,’may’,’june’))
print(“The length of the tuple is”, test)

Output:-

 

Use in Array =

test = len([‘Harry’,’Harmonie’,’Ron’, ‘Voldamort’])
print(“The length of the array is”, test)

Output:-

 

Thank you! ❤️

How to Use Input Function into Print() in Python!

Leave a Reply

Your email address will not be published. Required fields are marked *