编程语言
首页 > 编程语言> > Python 根据身份证号码计算持有者年龄

Python 根据身份证号码计算持有者年龄

作者:互联网

任务: 根据身份证号码计算持有者年龄

import datetime

id_card = '000000199912120000'
birth_year = int(id_card[6:10])
today_year = datetime.date.today().year
how_old = today_year - birth_year
print('今年{}岁'.format(how_old))

输出结果

今年22岁

标签:old,Python,datetime,how,身份证,year,持有者,id,today
来源: https://blog.csdn.net/realoser/article/details/122146408