Python len() Method
Description
Python len() method returns the length or number of items of an object (string, list, tuple, etc.).
Syntax
Syntax of len() method:
len( s )
Parameters
- s -- object.
Return Value
Returns the length of the object.
Example
The following example demonstrates the usage of len():
Example
#!/usr/bin/env python
# coding=utf-8
str = "example"
print( len(str) ) # string length
l = [1,2,3,4,5]
print( len(l) ) # number of list elements
After executing the above code, the output is:
6 5Other Extensions
Python Built-in Functions