小编BPm*_*rop的帖子

生成随机名称列表 - Python

我正在尝试创建一个名称列表,每个名称都不同。这是我现在的代码,但它所做的只是创建多个同名实例。

import random

first_names=('John','Andy','Joe')
last_names=('Johnson','Smith','Williams')

full_name=random.choice(first_names)+" "+random.choice(last_names)

group=full_name*3
Run Code Online (Sandbox Code Playgroud)

例如,这将显示为:

John Smith
John Smith
John Smith
Run Code Online (Sandbox Code Playgroud)

但我想要这样的东西:

John Williams
Andy Johnson
Joe Johnson
Run Code Online (Sandbox Code Playgroud)

python

6
推荐指数
1
解决办法
8万
查看次数

标签 统计

python ×1