Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I want my script to wait until the user presses any key.

How do I do that?

1 Answer

0 votes
by (106k points)

If you are using Python 3 version then you can use the following syntax to make a wait key:-

input("Press Enter to continue...")

If you are using Python 2, you should use raw_input(), as input(prompt) is equivalent to eval(raw_input(prompt)):

raw_input("Press Enter to continue...")

All these methods only wait for a user to press the enter button, so you might want to use msvcrt which works in Windows/DOS only. The msvcrt module gives you access to a number of functions in the Microsoft Visual C/C++ Runtime Library (MSVCRT)):

import msvcrt as m

def wait():

   m.getch()

So you can use it to make a program for a wait keypress.

If you wish to know what is python visit this python tutorial and python interview questions.

If you wish to learn more about Python, visit the Python tutorial and Python Certification course by Intellipaat.

Related questions

Browse Categories

...