Python随机生成手机号码小程序

做接口测试时,经常遇到入参包含手机号的接口,每次运行接口脚本就需要保持手机号不同,简单写个生成随机手机号的函数,随时调用,非常方便!

# -*- coding=utf-8 -*-

import random # 导入随机模块


def Random_Phone():
phone_list = ["130", "131", "132", "133", "134", "135", "136", "137", "138", "139", "147", "150", "151", "152",
"153", "155", "156", "157", "158", "159", "186", "187", "188", "173", "177", "180", "181", "189",
"199"] # 创建一个正确的手机前三位列表
random_phone = random.choice(phone_list) + "".join(random.choice("0123456789") for i in range(8))
"""
随机选取前三位,之后字符串拼接,随机选取数字循环8次
"""
return random_phone


print("随机生成的手机号为:{}".format(Random_Phone()))

Python随机生成手机号码小程序

上一篇:微信小程序——自定义组件时,编译报`Component is not found in path '...'`


下一篇:jenkins中编译go 代码时出现找不到文件路径问题