Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python len() method

Python len() method

Python built-in function Python built-in function


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

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

"

print

(

len

(

str

)

)

String Length

l

=

[

1

,

2

,

3

,

4

,

5

]

print

(

len

(

l

)

)

Number of elements in the list

The output of the code above is:

6
5

Python built-in function Python built-in function