Python中字符串的长度计算方法
发布时间:2023-12-14 12:42:45
在Python中,可以使用内置的len()函数来计算字符串的长度。该函数会返回字符串中字符的个数。
下面是一个使用len()函数的例子:
# 计算字符串的长度
string = "Hello, World!"
length = len(string)
print(f"The length of the string is: {length}")
输出结果为:
The length of the string is: 13
在上面的例子中,字符串"Hello, World!"的长度是13。
