How to jump out of a function in python

步履不停
Release: 2019-11-25 11:11:24
Original
31278 people have browsed it

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;
Copy after login
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;
Copy after login

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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!