作业帮 > 英语 > 作业

python string

来源:学生作业帮 编辑:作业帮 分类:英语作业 时间:2024/05/16 07:11:14
python string
求教:function name :
count_digits:
(str) -> int
描述:Return the total number of characters in the given string that are digits.For example,the String '123abc456' has 3 characters which are non-digits,and 6 characters which are digits.
这个应该怎写?
def count_digits(str):
count = 0
for c in str:
if c.isdigit():count += 1
return count