python string 的问题
发布网友
发布时间:2022-04-30 22:53
我来回答
共3个回答
热心网友
时间:2022-06-19 22:02
def count_digits(str):
count = 0
for c in str:
if c.isdigit():
count += 1
return count
if __name__ == '__main__':
print count_digits('Hello, 123456, wor100ld! 7890')
print count_digits('123abc456')
热心网友
时间:2022-06-19 22:03
def count_digits(str):
count = 0
for c in str:
if c.isdigit(): count += 1
return count
热心网友
时间:2022-06-19 22:03
>>> def count_digits(S):
return len([i for i in S if i.isdigit()])
>>> count_digits('123abc456')
6