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
      
      
  • 相关阅读:
    匿名内部类详解
    成员内部类详解
    内部类
    局部内部类详解
    switch
    Enum 类型
    循环
    标号
    软件开发模型
    RUP
  • 原文地址:https://www.cnblogs.com/pandaa/p/12034965.html
Copyright © 2011-2022 走看看