How can the size of a Python array be obtained?

In Python, you can use the len() function to get the size of an array or list. For example:

arr = [1, 2, 3, 4, 5]
size = len(arr)
print(size)  # 输出:5

Alternatively, to obtain the maximum index value of the array, you can use the len() function subtracted by 1. See example below:

arr = [1, 2, 3, 4, 5]
max_index = len(arr) - 1
print(max_index)  # 输出:4
Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds