python根据日期、随机数生成编码
作者:互联网
import datetime import random import string
"""
编码格式:YYYYMMDD 身份证后四位、四位随机数
"""
datetime_str = datetime.datetime.now().strftime('%Y%m%d') id_card = '340825198901113524' card_str = id_card[-4:] random_str = random.choices(string.digits, k=4) random_str = "".join(random_str) res_str = '%s%s%s' % (datetime_str, card_str, random_str)
print('res_str',res_str)
实现效果:
标签:编码,随机数,python,res,random,datetime,str,import,card 来源: https://www.cnblogs.com/1314520xh/p/16279413.html