A Python program to ask the user to enter name

Here I am going to explain a Python program to ask the user to enter a name. The task is going to be a very easy one. I will explain to you about the commands used in this program and how to write this program using a function.

A simple program to ask for the name in Python

NAME=str(input("enter the name: "))

Run the program


enter the name: user

hello user


The general description of this program is to ask a user name and save the data in “NAME” and to print the name using the variable where the data is stored.”NAME” is just a variable where the data is stored. Since we are asking name where no numbers are allowed so I am using string data type.

Ask the user to enter name in Python using a function

Let’s create our simple custom Python function and then call it:

def hello():
    name=str(input("enter the name : "))
    print("hello " + str(name))

Run this code online
And the output will be like you can see below:

enter the name : user

hello user

Here I had altered the general program by using a function. The hello() is a user-defined function used in this program and the function generated in a custom way. In this function, it is programmed to get the user name and to print the user name with a string “hello”.

So you can see that the same functionality is done by defining our own function.


I hope that I had demonstrated the program using function and in a simple way for your understanding.

Also read:

6 responses to “A Python program to ask the user to enter name”

  1. Praveena B says:

    Easy to understand

  2. siva priya says:

    you are doing great,make most of it da

  3. sam says:

    didn’t work i done this before i done this in php and shell not with this exact line of code but similar, mostly.

  4. Gsam says:

    Thanks so much your website has helped my research a lot

  5. aint usea says:

    Write a function hello(lastname, firstname ), in the sense if called with hello(‘Adam’,
    ‘Cloud’), will print two lines:
    Hey Cloud Adam
    Hey Adam Cloud

    • Simion Onyore Okola says:

      fname=str(input(“enter first name: “))
      lname=str(input(“enter lastname: “))
      print(“Hey”, fname, “”, lname,)
      print(“Hey”, lname, “”, fname,)

Leave a Reply

Your email address will not be published. Required fields are marked *