在Python中,可以使用len()
函数来统计字符串的字符数量。例如:
string = "Hello World"
count = len(string)
print(count) # 输出:11
另外,还可以使用循环来遍历字符串并计数字符的数量。例如:
string = "Hello World"
count = 0
for char in string:
count += 1
print(count) # 输出:11
这两种方法都可以用来统计字符串中的字符数量。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:python提取字符的方法是什么