How to view the length of a list in Python?
In Python, you can use the built-in function len() to get the length of a list. This function takes an iterable object (such as a list) as a parameter and returns the number of elements it contains.
Here is an example code using the len() function to get the length of a list:
my_list = [1, 2, 3, 4, 5]
length = len(my_list)
print(length) # 输出:5
In the example above, we created a list named my_list, then used the len() function to retrieve its length and stored the result in the variable length. Finally, we printed out the length (i.e. the number of elements in the list).
Remember, the len() function is not only limited to lists but also applies to other iterable objects, such as strings, tuples, and more.