len(iterable )
iterable :input iterable or string or any sequence my_str='plus2net.com'
print(len(my_str)) #12
Using list
my_list=['Welcome','to','plus2net']
print(len(my_list)) # 3
my_list=[2,3,1,5]
print(len(my_list)) #4
Using tuple
my_tuple=(5,2,3,6)
print(len(my_tuple)) #4
Using Dictionarymy_dict={1:'A',2:'B',3:'C'}
print(len(my_dict)) # 3
Using set
my_set={2,4,1,5}
print(len(my_set)) # 4
Using frozenset()
my_set={4,3,2,1,7}
my_set=frozenset(my_set)
print(len(my_set)) # 5
text = "plus2net"
print(len(text)) # Output: 8
numbers = [1, 2, 3, 4, 5]
print(len(numbers)) # Output: 5
nested_list = [1, [2, 3], 4, [5, 6]]
print(len(nested_list)) # Output: 4
data = {"name": "Alice", "age": 25, "location": "Paris"}
print(len(data)) # Output: 3
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.