程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Implementation of Python function nested call

編輯:Python

Function nesting refers to defining or calling another function in one function .
The following are simple examples to describe how to define and call another function in one function :
1. Define a function in a function

def outfun():
def infun1():
print(" This is an internally nested function 1")
def infun2():
print(" This is an internally nested function 2")
infun1()
infun2()
outfun()

stay python After running in the interpreter , The execution result is :
This is an internally nested function 1
This is an internally nested function 2

2. Call a function in a function

def test1():
print("*" * 20)
print("test1~~~")
def test2():
print("-" * 20)
print("test2~~~")
test1()
print("-" * 20)
test2()

stay python After running in the interpreter , The execution result is :
####################
test2~~~
1********************1
test1~~~
####################

call test1 Function time , First, complete the function test1 All tasks in .
Return call test2 Middle function test1 The location of , Then continue the execution of subsequent code .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved