How is the length of a Python string calculated?

In Python, you can use the built-in function len() to calculate the length of a string. For example:

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

In the above code, the len() function is used to calculate the length of the string ‘string’ and assign the result to the variable ‘length’. Finally, the length of the string is printed using the print() function.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds