logo

Three Ways to Pause a Program in Python 📂Programing

Three Ways to Pause a Program in Python

Code 1

input()

input()

No need to import a module, and as it does not display any message, it is the most convenient and frequently used method. The program pauses while waiting for input, but there’s no issue with its pause functionality as the input does not need to be stored.

time.sleep()

import time

time_duration = 3.5
time.sleep(time_duration)

Pauses for the specified amount of time. It is used when writing programs, such as web crawlers, that need to consider time delays.

os.system("pause")

import os

os.system("pause")

Directly issues a pause command to the terminal. This pause outputs messages such as Press any key to continue. or Press the <Enter> key to continue: automatically. It is often used to prevent the terminal from closing automatically after program termination.

Environment

  • OS: Windows
  • Python: 3.9.4