How do I count the length of a string in Python?
06May, 2022
How Can We Help?
Created On
byMatt
Print
You are here:
< Back
Maker of websites,
Teacher,
Cat enthusiast
Teacher,
Cat enthusiast
Latest posts by Matt (see all)
- The 2022 End of Year Website Update - 01/01/2023
- Celebrating Ada Lovelace day - 10/10/2022
- Website update 5/9/22 - 05/09/2022
Python has a specific function to find the length of strings called len().
x = "An example"
print(len(x))
Another way to count the length of a string would be to loop through the string since Python stores it as an array and count the number of characters.
count = 0
for x in "An example":
count = count+1
print (count)
Matt
administrator
Maker of websites,
Teacher,
Cat enthusiast