欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

如何用 python 生成随机手机号码

最编程 2024-04-08 14:50:11
...
import time


def get_mobile():
    mobiles = ['130', '131', '132', '133', '134']
    number  = str(int(time.time()))[2:]
    mobile  = random.choice(mobiles)+number
    return mobile

print(get_mobile())

知识点:

1.列表的使用(用于手机号码的开头)

2.使用python自带的时间戳进行截取(因为时间戳每次都不相同,所有可以用作随机生成)

3.随机选择random.choice(),可以在自己写的列表里面随机选择

4.字符串的拼接(+的使用)