zoukankan      html  css  js  c++  java
  • Python 参数,嵌套函数 的变量 使用

    1. *args 把所有位置参数 聚合到 元组中

    2. **kwargs 把所有的关键字参数 聚合到字典中

    3. ‘*’在函数的调用时,代表打散

    4. 默认参数的陷阱!

      def func(name,alist=[]):
          alist.append(name)
          return alist
      res = func('alex')
      res2 = func('panda')
      #res == ['alex']
      #res2 == ['alex','panda ']
      #如果 默认参数 指向一个可迭代的数据类型 
      
    5. 局部嵌套定义的函数 需要 用 nonlocal 声明

      def wrapper():
          count = 1
          def inner():
              nonlocal count
              count += 1
      
      
  • 相关阅读:
    2020 11 21
    2020 11 20
    2020 11 19
    2020 11 18
    2020 11 17
    2020 11 16
    2020 11 15
    2020 11 14
    2020 11 14
    第五周学习进度报告
  • 原文地址:https://www.cnblogs.com/pandaa/p/12034965.html
Copyright © 2011-2022 走看看