Python

Text Input

Want to get keyboard input?

To get keyboard input, use the input function.

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.

Related Courses: Complete Python Bootcamp: Go from zero to hero in Python

User Input

To get a text value:

name = input("Enter a name: ")
print(name)

This will show you:

Enter a name:

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

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"))

Previous Post Next Post

Cookie policy | Privacy policy | ©