在Python中退出程序,您可以使用以下方法:
1. 使用 `exit()` 或 `quit()` 函数:
>>> exit()
或
>>> quit()
然后按回车键退出Python解释器。
2. 使用 `Ctrl + Z` 组合键,然后按回车键:
C:\> python
Python X.X.X (default, Date, Time) [COMPILER] on PLATFORM
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
在Linux或macOS终端中,您可以这样操作:
$ python
Python X.X.X (default, Date, Time) [COMPILER] on PLATFORM
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
3. 使用 `Ctrl + D` 组合键(在Linux和macOS中):
$ python
Python X.X.X (default, Date, Time) [COMPILER] on PLATFORM
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
以上方法适用于退出Python交互式环境。如果您在编写Python脚本并希望退出脚本执行,只需在脚本最后添加 `exit()` 函数即可。