with open('data.txt', 'r', encoding='utf-8') as f:
for i in f.readlines():
if i[:4] == '身份证号':
print(i[:11] + '*' * 8 + i[19:].strip())
elif i[:3] == '手机号':
print(i[:7] + '*' * 4 + i[11:].strip())
else:
print(i.strip())
扫描下方二维码,关注后了解更多精彩内容!!