Teach Me Python #4: Input Statements

About: 1 new python tutorial every day Comment what you want the next one to be Please favourite and subscribe Notice Board: - since instructables has automatically been removing my indentations from this point o...

So far in this tutorial series, we have created simple programs that do not require any user input. However today we will begin to learn about input statements which take a user input from what the person running the program types. As always please favourite, comment and subscribe

Step 1: The Code

After opening a blank python file type the following code:

userName = input('What is your name ')
print('Hello', userName)

How this works is that on the first line the computer is creating a variable called userName, what happens next is the variable userName gets filled with whatever is typed by the user at that point. The computer will wait until the enter key is pressed before continuing Which allows strings of multiple characters to be entered.


Whatever you type into an input statement it will always be an string. To create an integer you would type:

userAge = int(input('How old are you? '))


userAge = input('How old are you? ')
userAgeInt = int(userAge)

We will go over the use of int() later in the series

The syntax for an input statement is:
variableName = input('optional prompt')

You may have noticed in the first example how we put a few spaces at the end of the prompt, this is because otherwise it would force you to begin typing your input right up next to the last word of the prompt and as well how i say the prompt is optional because if you just type input() it will still request an input but it won't have the prompt there to tell you what to type.



    • Faux-Real Contest

      Faux-Real Contest
    • Safe and Secure Challenge

      Safe and Secure Challenge
    • Comfort Food Challenge

      Comfort Food Challenge

    3 Discussions


    3 years ago

    I love this tutorial, I was doing cousera python course, and I got stuck for hours on the input function, 10 min with this tutorial and I totally understood what I was doing wrong.
    Thank you :-)

    1 reply
    BlueBlood Studiostalia1138

    Reply 3 years ago

    I love hearing things like this! although I stopped the python tutorials, I am thinking of creating a new series on modding games or a different language entirely