1.统计小写字母的个数
>>> def count_letter(s):
... result=0
... for i in s:
... if i>='a' and i<='z':
... result+=1
... return result
...
>>> count_letter("a1b3z4")
3
>>>
2统计一句话中的数字.
>>> def count_digits(s):
... result=0
... for i in s:
... if i>='0'and i<='9':
... result+=1
... return result
...
>>> print(count_digits("a1b2b4b5"))
4
>>>
3.统计一句话中的数字
>>> def count_digits(s):
... result=0
... for i in s:
... if i>='0' and i<='9':
... result+=1
... return result
...
>>> print(count_digits("a1b1c3d4"))
4
4.练习:两数相加
>>> def add(a,b):
... if isinstance(a,(int,float,complex)) and isinstance(b,(int,float,complex)):
... return a+b
... print("one of two parameters is not a number type.")
... return None
...
>>> print(add(1,"2"))
one of two parameters is not a number type.
None
>>>