len(s)
用来判断对象的长度。

需要说明的是,整型,布尔等是没有长度这一说法的。字符串、字典、列表和元组都有长度。

例子:

>>> len(123)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object of type 'int' has no len()
>>> len('hello')
5
>>> len(True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object of type 'bool' has no len()
>>> len([1,2,3,])
3
>>> len({'name':'tom','':'',})
2

 

相关文章:

猜你喜欢
  • 2022-02-22
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
  • 2021-06-08
  • 2021-07-14
  • 2022-01-07
相关资源
相似解决方案