Google News
logo
Python Program to Return the length of a string
In the following example of Python program that demonstrates how to return the length of a string using the built-in len() function :
Program :
# Return the length of a string
my_string = "Hello, World!"
string_length = len(my_string)

print("The length of the string is:", string_length)
Output :
The length of the string is: 13
In this program, we start by assigning the string value `"Hello, World!"` to the variable `my_string`. We then use the `len()` function to get the length of `my_string`, and assign the result to the variable `string_length`.

Finally, we use the `print()` function to print the message "The length of the string is:" followed by the value of `string_length`.

As you can see, the length of the string "Hello, World!" is 13 characters, which is what the `len()` function returns.