Home >Backend Development >Python Tutorial >How Can I Pause a Python Script Until the User Presses a Key?
Waiting for User Key Input in Python
In Python, there are several ways to make a script pause until the user presses any key.
Python 3
For Python 3, use the input() function:
input("Press Enter to continue...")
This will halt execution until the user presses Enter.
Python 2
For Python 2, use the raw_input() function instead:
raw_input("Press Enter to continue...")
However, both input() and raw_input() only wait for the user to press Enter.
Windows/DOS
On Windows/DOS systems, you can use the msvcrt module to achieve this:
import msvcrt as m def wait(): m.getch()
The wait() function will pause execution until any key is pressed.
Notes:
The above is the detailed content of How Can I Pause a Python Script Until the User Presses a Key?. For more information, please follow other related articles on the PHP Chinese website!