Python Forum
Hello world! program, window disappears - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Hello world! program, window disappears (/thread-8997.html)



Hello world! program, window disappears - nerio - Mar-16-2018

Hello.

I am a beginner in Python coding.

I wrote hello world program.

print('Hello, world!')
But when I run it on Windows 10, the window appears and disappears. What can I do to make it stay until I press a key?

I found this: https://stackoverflow.com/questions/983354/how-do-i-make-python-to-wait-for-a-pressed-key

but it didn't really help.. Thank you.


RE: Hello world! program, window disappears - wavic - Mar-16-2018

How do you run the program? Try to put this line:
_ = input()
And when you run the program hit Enter when it stops.


RE: Hello world! program, window disappears - buran - Mar-16-2018

just
input()
will suffice

or run your script from command prompt, not by double-click on it


RE: Hello world! program, window disappears - knackwurstbagel - Mar-16-2018

The question has been answered but I would like to add my two cents. While you are learning python you might benefit from simply running your python scripts directly from the terminal. Because when you start learning, you're not creating gui programms but rather your making command line programs. You do so by typing python or python3 followed by the name of your python script file. You may also benefit by knowing that from the terminal you can type python3 on its own and access a interactive python interpreter. The advantage to doing this is that you can learn a lot more by doing things yourself. Typing things like 4+5, you will be surprised what you can learn.