How to find length of string in Python
In this article, we will go through different methods to find the length of string in Python.
Method 1: len()
str = "Pythonpoint" print (len(str))
Output:
11
Method 2: for loop
str = "Pythonpoint" count = 0 for i in str: count += 1 print (count)
Output:
11
Method 3: while loop and slicing
str = "Pythonpoint" count = 0 while str[count:]: count += 1 print (count)
Output:
11
Note that, len() is the most efficient method.
Subscribe
Login
Please login to comment
0 Discussion