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

Python之第二十三天的努力--函数总结

时间:2020-06-28 22:43:33      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:global   class   python   rap   pre   报错   导图   free   inner   

01 函数总结

  • # 仅限关键字参数
    # def func(a,b,*args,c):
    #     print(a,b)
    #     print(c)
    #
    # func(1,2,3,4,c=666)
    
    
    
    # *
    # a,b = (1,2)
    # a,b,*c = (1,2,3,4,5,6)
    # print(a,b,c)                # 1 2 [3, 4, 5, 6]
    
    # a,*b,c = [11,22,33,44,55,66,77]
    # print(a,b,c)                # 11 [22, 33, 44, 55, 66] 77
    
    # a,*b,c = range(10)
    # print(a,b,c)                # 0 [1, 2, 3, 4, 5, 6, 7, 8] 9
    
    
    
    # def func():
    #     global name
    #     name = ‘zs‘
    #
    # print(name)         # 报错
    # func()
    # print(name)         # zs
    
    
    
    # name = ‘kk‘
    # def func():
    #     global name
    #     name = ‘zs‘
    #
    # print(name)         # kk
    # func()
    # print(name)         # zs
    
    
    
    # def func():
    #     name = ‘zs‘
    #     def inner():
    #         nonlocal name
    #         name = ‘kk‘
    #     print(name)         # zs
    #     inner()
    #     print(name)         # kk
    #
    # func()
    
    
    
    # def wrapper(a):
    #     name = ‘zs‘
    #     def inner():
    #         print(a)
    #         print(name)
    #     return inner
    # ret = wrapper(‘kk‘)
    # print(ret.__code__.co_freevars)     # (‘a‘, ‘name‘)
    
  • 思维导图,见day14文件夹。

Python之第二十三天的努力--函数总结

标签:global   class   python   rap   pre   报错   导图   free   inner   

原文地址:https://www.cnblogs.com/szheng/p/13205076.html

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