Python Determine String Length

Document 对象参考手册Python3 Examples

Given a string, then determine the length of the string.

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

str = "example" print(len(str))

The output of the above code is:

6

Example 2: Using a loop to calculate

def findLen(str): counter = 0 while str[counter:]: counter += 1 return counter str = "example" print(findLen(str))

The output of the above code is:

6

Document 对象参考手册Python3 Examples

Other Extensions