用Python的Faker()库生成随机公司名字
发布时间:2024-01-02 12:52:35
import faker
# 实例化Faker对象
fake = faker.Faker()
# 生成1000个随机公司名字
for _ in range(1000):
company_name = fake.company()
print(company_name)
'''
Output:
1. Smith, Brown and Thompson
2. Davis and Sons
3. Reynolds Group
4. Anderson-Miller
5. Wilson, Hill and Foster
6. Rogers, Schultz and Davis
7. Harrison-Lee
8. Williams and Sons
9. White PLC
10. Taylor, Steele and Turner
...
996. Edwards, Fisher and Lucas
997. Cox, Walker and Thomas
998. Baker and Sons
999. Marshall, Castillo and Reed
1000. Nguyen, Wells and Sexton
...
'''
在上面的示例中,我们首先导入了 faker 库,并使用 faker.Faker() 创建了一个 fake 对象。
随后,通过循环生成1000个随机公司名字。为了生成随机公司名字,我们使用了 fake.company() 方法。
在每次循环中,我们将生成的公司名字打印出来。
最终,我们会得到1000个随机的公司名字,类似于示例输出中的结果。
