在Python中,是否有比使用循环更习惯的方法来计算字符串长度的总和?
length = 0
for string in strings:
length += len(string)
我尝试了sum()
,但它只适用于整数:
>>> sum('abc', 'de')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: sum() can't sum strings [use ''.join(seq) instead]