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 di

来源:学生作业帮助网 编辑:作业帮 时间:2024/04/29 15:09:10
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 di

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 di
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.
这个应该怎写?

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 di
def count_digits(str):
count = 0
for c in str:
if c.isdigit():count += 1
return count