len函数用于获取一个对象的长度或元素个数。它的使用方法如下:
string = "Hello World"
length = len(string)
print(length) # 输出:11
list1 = [1, 2, 3, 4, 5]
length = len(list1)
print(length) # 输出:5
tuple1 = (1, 2, 3, 4, 5)
length = len(tuple1)
print(length) # 输出:5
set1 = {1, 2, 3, 4, 5}
length = len(set1)
print(length) # 输出:5
dict1 = {"name": "John", "age": 25, "city": "New York"}
length = len(dict1)
print(length) # 输出:3
number = 12345
length = len(number)
print(length) # TypeError: object of type 'int' has no len()
总之,len函数可以用于获取字符串、列表、元组、集合、字典等对象的长度或元素个数。