Search code examples
pythonwindows

How to Prevent My Python Script from Closing Immediately After Running on Windows?


I'm just starting out with Python on my Windows computer. I wrote a simple script to print "Hello, World!" like this:

print("Hello, World!")

When I double-click the .py file to run it, a command prompt window briefly appears and then closes right away. I can't see the "Hello, World!" message.

How can I make the window stay open after the script finishes so I can read the output?

Thanks in advance!


Solution

  • you can use input function

    print("Hello, World!")
    input("Press Enter to exit...")