Python Determine the Length of a String
Given a string, determine its length.
Example 1: use the built-in len() method
str
=
"
runoob
"
(
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
"
(
findLen
(
str
)
)
The output of the code above is:
6
Python3 Examples