In this tutorial, you'll learn how to accept input in Python. Your programs will be able to read your own input from the "Input" tab (the second tab) when you hit "Try it now" buttons. Let's get started!
So far, we've only been printing values. However, it's also useful to accept input values — in fact, most real-world programs you write will have to accept input in one form or another. First, let's look at one of the simplest ways to accept input. Let's use the input function.
Take a look at the code below:
type=codeblock|id=py3_input|autocreate=python3|input=Commonloungename = input()print("Hello " + name + "!")
When you run the code above, it reads the user's name from the input tab (the second tab between Code and Output tabs. You'll see the tabs once you hit the Try it now button.) It then greets them by their name. For example, if the input is "CommonLounge", the program outputs:
Use the Try it now! button above, go to the Input tab and write your name, and then click Run.
Note: In general, the input() function keeps reading input till it sees an Enter (or a newline).