python中对比数组长度
The __len__() is a method on container types. However, python also provides another option of retrieving the length of an array, using the method len().
__len __()是关于容器类型的方法。 但是,python还使用len()方法提供了另一个检索数组长度的选项。
The len(abc) usually ends up calling abc.__len__().
len(abc)通常最终会调用abc .__ len __() 。
Example usage of len() method is as follows,
len()方法的示例用法如下,
# array declaration
test_arr = [1,2,3]
# length
print(len(test_arr))
print(test_arr.__len__())
Output
输出量
3
3
The len() method works on a tuple, string (which are array of characters) in similar way.
len()方法以类似的方式处理元组,字符串(字符数组)。
test_tuple = (1,2,3)
# length
print(len(test_tuple))
# string
test_str = 'include-help'
# length
print(len(test_str))
Output
输出量
3
12
翻译自: https://www.includehelp.com/python/preferred-way-to-retrieve-the-length-of-an-array.aspx
python中对比数组长度