Python's built-in functions (forty), len ()

description

The Python len () method returns the length of an object (characters, lists, tuples, etc.) or the number of items.

grammar

Syntax of len () method:

len( s )

parameter

  • s-object.

return value

Returns the object length.

Examples

The following example shows how to use len ():

>>>str = "runoob"
>>> len(str)             # 字符串长度
6
>>> l = [1,2,3,4,5]
>>> len(l)               # 列表元素个数
5

 

Published 943 original articles · Like 136 · Visit 330,000+

Guess you like

Origin blog.csdn.net/weixin_36670529/article/details/105282579