Home  >  Article  >  Backend Development  >  How to jump out of a function in python

How to jump out of a function in python

步履不停
步履不停Original
2019-07-02 13:32:4531527browse

How to jump out of a function in python

You can jump out of the function through break, continue, return.

#!/bin/python
#-*- coding -*-
def printinfo( nu, *others ):
  print nu
  for var in others:
                  print var
return;
Recommended manual:Basic introductory tutorial on Python
#!/bin/python
#-*- coding:utf-8 -*-
def printinfo( nu, *others ):
 print nu
 for var in others:
         print var
 return;

Two identical functions, passing the same value have different results. In one case, return is inside a for loop, so the output is once to exit the loop

>>> printinfos(11,12,13,15,112)
11
12
>>> printinfo(11,12,13,15,112)
11
12
13
15
112

break: jump out of the entire current loop and continue execution in the outer code.

continue: Jump out of this loop and continue running the loop from the next iteration. After the inner loop is executed, the outer code continues to run.

return: Return to the function directly, and all the code in the function body (including the loop body) will not be executed again.

Recommended related tutorials: Python video tutorial

Recommended related articles:
1.How to end and exit the python script
2.How to get out of the while loop in python
Related video recommendations:

1.小 Turtle Zero Basics Getting Started Learning Python Video Tutorial

The above is the detailed content of How to jump out of a function in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What can pythonista3 do?Next article:What can pythonista3 do?