How to terminate a Python script

前端 未结 10 1191
予麋鹿
予麋鹿 2020-11-22 04:34

I am aware of the die() command in PHP which exits a script early.

How can I do this in Python?

10条回答
  •  醉梦人生
    2020-11-22 05:07

    A simple way to terminate a Python script early is to use the built-in quit() function. There is no need to import any library, and it is efficient and simple.

    Example:

    #do stuff
    if this == that:
      quit()
    

提交回复
热议问题