Python fake name generator Using Python faker Library

Hello coders welcome to my new tutorial Python Fake Name Generator. In this tutorial you will learn to generate names using python faker library. Here I will teach you how to generate names by different ways using faker library in python.

Faker is the most popular python library to generate dummy or fake datasets. In this tutorial you will learn following things –

  • Generate fake names
  • Generate fake namess of different countries in different language
  • Generate names’s prefix
  • Generate name’s suffix
  • Generate first names and last names etc.

So without any delay let’s get started this interesting tutorial.

Python Fake Name Generator Using Python faker Library

Installing Faker Library In Anaconda Prompt

To use faker library we first need to install it in our system. So run following command in your anaconda prompt. This will install faker library in your system.

Generating Fake Names 

Now we will learn how to generate names using faker module. So let’s do it.

To generate fake data, we first need to create a faker object and then call methods to generate fake data as per our requirement.

Let’s understand it with code.

What We Did?

  • First of all we have imported faker module.
  • Then created an object of Faker class.
  • Now we have generated fake name by calling name() method by using the faker object.
  • And at the last we have printed the generated fake name.

We have written the code successfully, now lets run the code and check the output.

Python Fake Name Generator

So guys in the above output you can see a fake name is generated successfully.

Generating Localized Fake Name 

By default, faker generate data in English and US centric(en-US ). But we can also generate localized data. For eg. if we want to generate Indian names in English then we will have to pass locale parameter while creating the faker object.

Let’s see it with an example code.

  • en_IN is for English(India)

Let’s see its output.

Python Fake Name Generator

So guys, you can see an Indian name is generated in English name. What if you wanted to generate Indian name in Hindi language. You can do it by passing hi_IN parameter. Let’s see it with an example.

Let’s see its output.

Python Fake Name Generator

Awesome !!! So we can generate names of any country in any language. If you want to see all the countries and languages then check this link.

Are you guys enjoying this python fake name generator tutorial? Yes, then keep reading !!!

Generating Multiple Fake Names

Till now we have only generated one name at a time but what if we require to generate multiple fake names. So let’s see how to do that.

Generating multiple fake names using faker module is very simple. We just have to start a for loop. Let’s understand it with an example.

  • Here we have generated 5 fake names.


Python Fake Name Generator

So we have generated multiple names using faker module. Here we have only generated 5 names, you can do whatever you want.

Generating Male And Female Name

We can generate male and female names using faker library in following way.

  • name_female() method is used to generate female names.
  • name_male() method is used to generate male names.


Generating First And Last Name

Working with faker library is very easy because it provides very easy to remember methods to generate fake data. Some time we require first and last name. We can also generate first and last name using faker library.

first_name() method is used to generate first name and last_name() method is used to generate last name. So let’s implement them to get first and last name. Write and run following code to generate first and last name.


Here is its output.

We can also generate first and last name of male and female. Here is the code.


Generating Name’s Prefix and Suffix

Do you also want to generate name’s prefix and suffix? Here is the code to do that.

  • prefix() method is used to generate prefix.
  • suffix() method is used to generate suffix.

So guys it was all about Python Fake Name Generator tutorial. You have learned generating fake names in different ways using python faker library. I hope you found this tutorial easy and helpful. But still if you have any doubt then feel free to comment your queries. In upcoming tutorials, you will learn more faker tutorials like generating emails, credit cards, addresses phone numbers and many more. So stay tuned with Dggul AI Tutorial for more faker tutorials. THANKS

Related Articles… 

Leave a Comment