python字符串的长度如何计算

Python中可以使用内置函数len()来计算字符串的长度。例如:

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

在上述代码中,len()函数计算了字符串string的长度,并将结果赋值给变量length。最后,使用print()函数将字符串的长度打印出来。

阅读剩余
THE END