码迷,mamicode.com
首页 > 编程语言 > 详细

python基础-函数之装饰器、迭代器与生成器

时间:2017-07-24 09:54:38      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:1.2   log   turn   bar   int   rom   style   迭代   函数   

1. 函数嵌套

1.1 函数嵌套调用

  函数的嵌套调用:在调用一个函数的过程中,又调用了其他函数

def bar():
    print("from in the bar.")

def foo():
    print("from in the foo.")
    bar()

foo()

 

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

res = max4(2,5,3,-4)
print(res)

 

1.3 函数嵌套定义

函数的嵌套定义:在一个函数的内部,又定义另外一个函数

def f1():
    x = 1
    def f2():
        print("from f2.")
    f2()   # 只能在函数内部调用

f1()

 

 

 

 

python基础-函数之装饰器、迭代器与生成器

标签:1.2   log   turn   bar   int   rom   style   迭代   函数   

原文地址:http://www.cnblogs.com/goodshipeng/p/7226986.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!