Python中用于计算字符串长度的函数
发布时间:2023-06-05 15:07:42
Python中用于计算字符串长度的函数是len()函数。该函数可以返回一个字符串中字符的数量,包括空格和特殊符号在内。len()函数的语法格式如下:
len(str)
其中,str是要计算长度的字符串。
例如,下面是一个简单的例子,演示如何使用len()函数计算字符串长度:
str = "Hello, World!"
length = len(str)
print("The length of the string is:", length)
执行上述代码,输出结果为:
The length of the string is: 13
这表示字符串"Hello, World!"的长度为13个字符。
