本次仅用来练习函数的返回值,return语句的使用。
如果要准确的验证手机号码,需要使用到正则表达式。
思路:
1.判断字符串是否是数字
2.判断是否是11位数字
3.判断是否是数字1开头
def check_phone_num(phone_num):# 第一步检测手机号码长度是不是11位if len(phone_num) == 11:# 第二步检测是不是数字if phone_num.isdigit():# 第三步检测是不是数字1开头if phone_num.startswith('1'):# 前面三项都通过,则return返回bool值和phone_numreturn True, phone_nums = '18601749600'print(check_phone_num(s))