Keywords: Input, Python, Get input
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 ().
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.
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
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
Please leave feedback and help us continue to make our site better.
How useful was this article?
We are sorry that this post was not useful for you!
Let us improve this post!
Tell us how we can improve this post?