python中对比数组长度_在Python中检索数组长度的首选方法

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中对比数组长度

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值