...

/

Input and Assign to Variable

Input and Assign to Variable

Let’s see how we can take input from a user and save it for later use.

Taking input from a user

Let’s continue making our way into Python and the project. Notice that project requirements 1 and 5 are categorically different from requirement 2, which is printing something on the screen.

Press + to interact
The project requirements that require printing the output on the screen
The project requirements that require printing the output on the screen

Now we know how to print a name on the screen using Python, but how does our code ask the elementary school student to tell us their name?

The built-in input() function

Just like print prints something on the screen, what would be the name of the built-in function that takes input from the user’s keyboard? You guessed it! Python offers us another built-in function with the name of input.

Note: After clicking the “Run” button, click anywhere inside the black terminal window. When you see a blinking cursor, you will know that the program is waiting for your input. Use your keyboard to write anything and then press enter. Give it a shot:

input()
Taking the input using the input() function
...
Access this course and 1400+ top-rated courses and projects.