python笔记:将数字转换为字符串ID 本质上是将十进制转换为26进制 ```python import random import time def int_to_char(input) -> str: return chr(input + 97) def get_code(input=0) -> str: """ 0 - a 1 - b 25 - z 26 - aa """ if input == 0: # 12位数正好可以到8位小写 # zzzzzzzz = 2088270645 75 = 2036-03-05 03:10:45 # baaaaaaa = 80318101 76 = 1972-07-18 22:35:01 input = int(time.time())*100 + random.randint(1, 99) result = "" while True: quotient = input // 26 remainder = input - quotient * 26 input = quotient result = int_to_char(remainder) + result if quotient < 26: if quotient == 0: break result = int_to_char(quotient) + result break return result # print(get_code(208827064575)) # print(get_code(8031810176)) print(get_code()) ``` 也可以拼动物,这就不实现了: ``` year_tag = [‘lion’, ‘leopard’, ‘panda’, ‘tiger’, ‘wolf’, ‘zebra’, \ ‘bull’, ‘cow’, ‘calf’, ‘buffalo’, ‘goat’, ‘sheep’, ‘lamb’,\ ‘bear’, ‘camel’, ‘deer’, ‘elephant’, ‘fox’, ‘giraffe’, ‘horse’, \ ‘pig’, ‘dog’, ‘monkey’, ‘bat’, ‘cat’, ‘kangaroo’, ‘hedgehog’, \ ‘squirrel’, ‘rabbit’, ‘rat’, ‘dolphin’, ‘whale’, ‘seal’, \ ‘tortoise’, ‘crocodile’, ‘hippopotamus’, ‘fish’, ‘shrimp’, \ ‘crab’, ‘lobster’, ‘snail’, ‘frog’, ‘snake’, ‘worm’, ‘cock’, \ ‘hen’, ‘chick’, ‘duck’, ‘mouse’, ‘dragon’, ‘chicken’, ‘bird’,\ ‘eagle’, ‘pigeon’, ‘dove’, ‘owl’, ‘bee’, ‘butterfly’, ‘fly’, ‘hippo’] ``` 来自 大脸猫 写于 2016-08-26 15:49 -- 更新于2023-07-20 17:23 -- 0 条评论