python读取身份证中的生日信息
编写程序输入一个列表,列表中的元素为身份证(18位),根据身份证号获得生日信息,说明身份证的7到10表示出生年,11到12表示出生月,13到14表示出生日。
输入:
id_cards = ['310101199005052115', '320507199812280150']
输出:
310101199005052115:1990/05/05 320507199812280150:1998/12/28
程序代码
#!/usr/bin/python
# -*- coding: UTF-8 -*-
"""
@author: Roc-xb
"""
def get_birthday(id_card):
year = id_card[6:10]
month = id_card[10:12]
day = id_card[12:14]
print("{}:{}/{}/{}".format(id_card, year, month, day))
if __name__ == '__main__':
id_cards = ['310101199005052115', '320507199812280150']
for id_card in id_cards:
get_birthday(id_card)