lettura simple

How to take user input in Python

In this lesson I'll explain how to use the input function in Python language through a practical example.

What is the input function used for? The input() function suspends execution of the program and asks the user to type something. When the user gives enter, the program assigns the content typed by the user to a variable.

Write this script.

example code

The first line of the code prints the message "what's your name" on the screen and asks the user to type their name.

how to works the code

The user types his name (eg Tom) and gives enter.

user type a name

The script receives the text written by the user and records it in the variable name.

Finally, the script displays the string "Hello" followed by the user's name registered in the variable name.

how to use input function in python

It is a very simple example but it gives an idea of how the input() function works in python.

If you like this lesson from Nigiara continue to follow us.




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin