运行程序后窗口立即关闭 [英] Window closes immediately after running program

查看:48
本文介绍了运行程序后窗口立即关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是所有编程的新手,我刚刚开始对学习如何编程产生兴趣.为此,我从大多数人认为最简单的语言开始:Python.

I am new to all programming and I just started to get interested in learning how to program. So to do so I started with what most people consider the easiest language: Python.

我现在遇到的问题是,如果我对 Python print("Hello!") 说,将其保存在一个文件中,然后运行它,则会打开一个黑色窗口并立即关闭.我只是不明白它为什么要这样做.

The problem I am having right now though is that if I say to Python print("Hello!"), save it in a file, and then run it, a black window opens up and closes right away. I just do not understand why it is doing this.

推荐答案

程序运行完成后窗口立即关闭是正常的.如果您希望它保持打开状态,可以添加对 input<的调用/code>(或 raw_input 如果您使用的是 Python 2.x) 最后:

It is normal for the window to close as soon as your program runs to completion. If you want it to stay open, you can add a call to input (or raw_input if you are using Python 2.x) at the end:

print("Hello!")
input("Press the <Enter> key on the keyboard to exit.")

这将使窗口保持打开状态,直到您按下键盘上的 Enter 键.

This will keep the window open until you press the Enter key on the keyboard.

这篇关于运行程序后窗口立即关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆