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

Python Determine the Length of a String

Python Determine the Length of a String

Document Object Reference Manual Python3 Examples

Given a string, determine its length.

Example 1: use the built-in len() method

str

=

"

runoob

"

print

(

len

(

str

)

)

The output of the code above is:


6

Example 2: compute with a loop

def

findLen

(

str

)

:

counter

=

0

while

str

[

counter

:

]

:

counter

+=

1

return

counter

str

=

"

runoob

"

print

(

findLen

(

str

)

)

The output of the code above is:


6

Document Object Reference Manual Python3 Examples