一、使用字符串拼接输出一个关于程序员的笑话
programmer_1='程序员甲:搞IT太辛苦了,我想换行……怎么办?'
programmer_2='程序员乙:敲一下回车键'
print(programmer_1+programmer_2)
二、截取身份证号码中的出生日期
programer_1='你知道我的生日吗?'
print('程序员甲说:',programer_1)
programer_2='输入你的身份证号码。'
print('程序员乙说:',programer_2)
idcard='123456199006277890'
print('程序员甲说:',idcard)
birthday=idcard[6:10]+'年'+idcard[10:12]+'月'+idcard[12:14]+'日'
print('程序员乙说:','你是'+birthday+'出生的,所以你的生日是'+birthday[5:])
三、输出被@的好友名称
str11='@明日科技 @扎克伯格 @俞敏洪'
list1=str.split('')
print('您@的好友有:')
for item in list1:
print(item[1:])
四、通过好友列表生成全部被@的好友
list_friend=['明日科技','扎克伯格','俞敏洪','马云','马化腾']
str_friend='@'.join(list_friend)
at='@'+str_friend
print('您要@的好友:',at)
五、验证输入的手机号码是否为中国移动的号码
import re
pattern=r'(13[4-9]\d{8})$|(15[0129]\d{8})$'
mobile='13634222222'
match=re.match(pattern,mobile)
if match==None:
print(mobile,'不是有效的中国移动号码。')
else:
print(mobile,'是有效的中国移动号码。')
mobile='13144222221'
match=re.match(pattern,mobile)
if match==None:
print(mobile,'不是有效的中国移动号码。')
else:
print(mobile,'是有效的中国移动号码。')
标签:号码,程序员,mobile,idcard,print,python5,match From: https://www.cnblogs.com/666k/p/16966976.html