Python記錄8:函式的巢狀
阿新 • • 發佈:2018-12-05
#函式的巢狀分為兩類:
# 1.函式的巢狀定義: 在函式內部又定義了一個函式
# def foo():
# x=1
# # print(x)
# def bar():
# print('from bar')
#
# bar()
# foo()
# from math import pi
#
# def circle(radius,types=0):
# def perimiter(radius):
# return 2 * pi * radius
#
# def area(radius):
# return pi * (radius ** 2)
#
# if types == 0:
# res=perimiter(radius)
# elif types == 1:
# res=area(radius)
# else:
# print('不支援的操作,types必須傳入0或者1')
#
# return res
# circle(10,1)
# 2.函式的巢狀呼叫: 在呼叫一個函式的內部又呼叫其他函式
# def max2(x,y):
# if x > y:
# return x
# else:
# return y
#
# def max4(a,b,c,d):
# res1=max2(a,b)
# res2=max2(res1,c)
# res3=max2(res2,d)
# return res3
#
# print(max4(1,2,3,4))