Count the length of a string

Last updated 7 months, 2 weeks ago | 402 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.