w3resource logo


Python Exercises

Python: Write a Python program to calculate the length of a string


Write a Python program to calculate the length of a string.

Sample Solution :

Python Code :

def string_length(str1):
    count = 0
    for char in str1:
        count += 1
    return count
print(string_length('w3resource.com'))

Console :

Copy and paste the above code and press "Enter key" to execute :

Contribute your code and comments through Disqus.

Test your Programming skills with w3resource's quiz.