Want to get keyboard input?

To get keyboard input, use the input function. Inside the terminal you’ll be able to type text.

In Python 3 you can use the input() function, older versions of Python have the raw_input() function.

Related Courses:

User Input

The input function has a return variable. In this case the keyboard input. If we do not store the return variable into a programs variable, we lose it. That’s why we write a variable to store the result in.

To get a text value:

name = input("Enter a name: ")

This will show you:

Enter a name:

You can now give keyboard input, it will be stored in the variable name.

keyboard input

Note: don’t forget to store the return variable. variable = input(“..”)

Numeric input

To get a whole number:

x = int(input("What is x? "))

To get a decimal number:
x = float(input("Write a number"))

Download exercises