How to wait input from keyboard in Python

I want my program to wait input text.

Not only Python but also other program, you want it to wait input from keyboard.

But what should we write to wait input.

Today I will introduce about "How to wait input from keyboard in Python".


Get character from keyboard

In order to get character from keyboard, we use "standard input".

"Standard input" means standard source of input.

It is abstracted. But you can consider "standard input" as "keyboard input".

In computer programming, standard streams are preconnected input and output communication channels between a computer program and its environment when it begins execution. The three input/output (I/O) connections are called standard input (stdin), standard output (stdout) and standard error (stderr). Originally I/O happened via a physically connected system console (input via keyboard, output via monitor), but standard streams abstract this.

Standard streams – Wikipedia

So in Python, we also use "standard input".

How to wait input in Python

How to wait input in Python

In order to wait input, we can use input function.

We can use it like following.

var = input("Please input variable : ")
print("Input variable is : {}".format(var))

Once you execute it, it will wait input like below.

Please input variable : 

If you input text and push Enter, program would resume the process.

Please input variable : aaa
Input variable is : aaa


In case of input from console, you can use input function.

raw_input was expired in python3.

Receive standard input


Today I described about "How to wait input from keyboard in Python".

Important points are following.

If you want to wait input from keyboard, you can use input function in python.

Standard input is basic. But it is useful.

Once we understand standard input, our program will become smarter.

Let's use it.

いいね または フォローしてね!

If you like this article, please share !
  • URLをコピーしました!
  • URLをコピーしました!


karasanのアバター karasan System engineer

Mid-career engineer (AI, Data science, Salesforce, etc.).
Good at Python and SQL.