在Python中,你可以使用sys.exit()
函数来停止程序的执行
import sys
print("This is a sample Python script.")
# 你可以在任何地方调用 sys.exit() 来停止程序
sys.exit(0) # 0 表示正常退出,非零值表示异常退出
print("This line will not be executed.")
在这个例子中,当你运行这个脚本时,它会先打印 “This is a sample Python script.”,然后调用 sys.exit(0)
来停止程序的执行。因此,“This line will not be executed.” 这一行将不会被打印出来。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:python停止命令在哪执行