Inputs in Python


Keywords: Input, Python, Get input

Input in Python learn programming

If you want to send data (inputs) to the computer that the program can use, inputs are easily made in Python with the function input ().

What is an input in Python and why use input in Python?

Often, a user needs to provide information (inputs) to the program he or she is using. For example, it may be a name, age or other information that the program needs to know to function as intended. For example, you have at some point entered information in a dialog or form. This information must be able to save and interpret the computer. Therefore, Python has pre-programmed functions to easily manage inputs.

How do you create an input in Python?

In Python,

  • There are preprogrammed functions for managing inputs
  • With the input () method, you can easily enter values into the program
  • When using the function, the program will wait until the user has entered something in the console and then continue in the program.

Syntax for Input in Python

You can use the input () function with the following syntax:

name = input("Information")

Within the parentheses you write the information to the user, typically the information requested by the user. In this case, the value that the user enters will be saved in the name variable.

When using the function, the program will wait until the user has entered something in the console and then continue with the program

Example for Input in Python

In the following example, we test how to use the input () function in Python. We ask the user to enter their name. Once the user has entered their name (and pressed enter), the program continues. In this case, the program will print “Hello name, welcome to Code-Knowledge Python!”.

name = input("What is your name? ")

print("Hi {},".format(name), "welcome to Code-Knowledge Python!")

We will get an input field in the console where the user can type their name (our input)

What is your name? Carl

The result, in this case the print of the text in the console, will be

Hi Carl, welcome to Code-Knowledge Python!

Note that there is a space in the prompt “What is your name? “. This is to get a space between the input box and the prompt, which perhaps makes the program a little more stylish.

If you do not remember how to format printouts in Python, you can go back a few articles and look at: Prints in Python article