Count the length of a string

Last updated 4 months, 1 week ago | 173 views 75     5

Tags:- Python

In Python, you can count the length of a string using the len() function.

text = "Hello, World!"
length = len(text)
print("Length of the string:", length)


# Output: Length of the string: 38

The len() function counts all characters, including spaces and punctuation.