# python读取身份证中的生日信息

> 来源：梦飞idc云平台 | 原文：https://www.mfisp.com/12810.html | 发布：2022-11-17 | 更新：2022-11-17 | 分类：建站教程、投稿分享

编写程序输入一个列表，列表中的元素为身份证（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)

 

![python读取身份证中的生日信息](https://www.mfisp.com/wp-content/uploads/2022/01/13e1e49bb26b66e_1_post.png)

---
本页由 梦飞idc云平台（https://www.mfisp.com）提供。站点导航见 https://www.mfisp.com/llms.txt
