You are currently viewing How to Find Length of String in Python

How to Find Length of String in Python

The len() function is the simplest way to find length of string in Python. All you have to do is pass the string as an argument to the len() function, and it will return the length of the string. If you want to find the length of a string without using the len() function, you can loop through the string and count the number of characters.

The len() function is the simplest way to find length of string in Python. All you have to do is pass the string as an argument to the len() function, and it will return the length of the string. If you want to find the length of a string without using the len() function, you can loop through the string and count the number of characters.

Method 1: Find Length of String using len()

str = "AiOcta"
print("Length of the String is = ", len(str))

Output:

Length of the String is =  6

Method 2: Find Length of String using FOR Loop

a = 0
for i in "AiOcta":
    a = a + 1
print("Length of the String is = ", a)

Output:

Length of the String is =  6

Reference:

https://docs.python.org/3/

Leave a Reply