Python String Length: Using len() Function

In Python, you can use the built-in function len() to get the length of a string. This function returns the number of characters in the string (including spaces, punctuation, etc.). Here is a simple example:

my_string = "Hello, World!"
length = len(my_string)
print(length)  # 输出:13

In the example above, the len() function is used to obtain the length of the string my_string and then print the result.

bannerAds