Python len() function
Python len() function
The len() function in Python returns the number of items in an object.
Syntax
len(s)
Parameter
s: This parameter represents a sequence (such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set).
Return
This function returns the length (the number of items) of an object.
Example 1
# Python Program explaining # the len() function inp_list = ["Monday", "Tuesday", "Wednesday"] len_val = len(inp_list) print("Total length: ",len_val)
Output
Total length: 3
Example 2
# Python Program explaining # the len() function int_str = "example" print(len(int_str)) int_str = "tutorials and example" print(len(int_str))
Output
7 21