LEN成本()函数函数、成本、LEN

2023-09-10 22:31:54 作者:Whisper呢喃

什么是 )的成本len个( 功能Python的内置插件? (列表/元组/串/字典)

What is the cost of len() function for Python built-ins? (list/tuple/string/dictionary)

推荐答案

这是 O(1)(非常快)你所提到的每一种类型,加上设置和其他如 array.array

It's O(1) (very fast) on every type you've mentioned, plus set and others such as array.array.