📜  len python (1)

📅  最后修改于: 2023-12-03 14:43:52.431000             🧑  作者: Mango

Introduction to len function in Python

len is a built-in function in Python that returns the length of an object. The object can be a string, list, tuple, dictionary or any other iterable.

Syntax
len(object)

The object parameter is the object for which we want to find the length.

Examples
Finding length of a string
text = "Python is awesome"
print(len(text))  # Output: 17
Finding length of a list
numbers = [1, 2, 3, 4, 5]
print(len(numbers))  # Output: 5
Finding length of a dictionary
ages = {"John": 25, "Jane": 30, "Sam": 21}
print(len(ages))  # Output: 3
Conclusion

The len function is a useful tool for finding the length of an object in Python, whether it's a string, list, tuple, dictionary or any other iterable.