In this Python tutorial, we will learn how to find the length of a string using len() builtin function.
Python – String Length
To find the length of a string in Python, use the function len() and pass the string as argument.
len() function returns an integer value representing the number of characters in the string.
Syntax
The syntax of len() function is
</>
Copy
len(string)
Examples
1. Find length of a string
In the following example, we take a string value and find its length. We print the length to the console.
Python Program
</>
Copy
str = "Welcome to TutorialKart."
length = len(str)
print("Length of the string is :", length)
Output
Length of the string is : 24
2. Length of empty string
Let us take an empty string and find out its length. Of course it has to be zero.
Python Program
</>
Copy
str = ""
length = len(str)
print("Length of the string is :", length)
Output
Length of the string is : 0
Conclusion
In this Python Tutorial, we learned how to find the length of a string in Python using len() function.