Python len() method
Description
The Python len() method returns the length of an object (string, list, tuple, etc.) or the number of items.
Syntax
len() method syntax:
len( s )
Parameters
- s -- the object.
Return Value
Returns the length of the object.
Example
The following example shows how to use len():
Example
#!/usr/bin/env python
coding=utf-8
str
=
"
runoob
"
(
len
(
str
)
)
String Length
l
=
[
1
,
2
,
3
,
4
,
5
]
(
len
(
l
)
)
Number of elements in the list
The output of the code above is:
6
5
Python built-in function