zoukankan      html  css  js  c++  java
  • python函数参数总结

    python中函数参数有:默认参数、关键字参数、非关键字可变长参数(元组)、关键字可变长参数(字典)

    默认参数:在函数声明时,指定形参的默认值,调用时可不传入改参数(使用默认值)
    def foo(x): ##默认参数
      print 'x is %s' % x
    关键字参数: y默认为20
    def foo( x,y=20): ##关键字参数
      print 'x is %s' % x
      print 'y is %s' % y
    非关键字可变长参数(元组):*z接收一个元组
    def foo(x,y=20,*z): ##默认参数
      print 'x is %s' % x
      print 'y is %s' % y
      for myz in z:
        print 'z: ', myz
    关键字可变长参数(字典):**w接收的是一个字典
    def foo(x,y=20,*z,**w):  ##默认参数
      for wArg in w.keys():
            print 'wArg %s: %s' % (wArg, str(w[wArg]))






  • 相关阅读:
    mvn
    MySQL 数据类型
    Request获取客户端IP
    struts1
    tomcat8.5 Host-Manager配置访问的方法
    struts2框架
    windows注册表
    windows常用命令
    浏览器内核
    创建分区swap分区
  • 原文地址:https://www.cnblogs.com/seablog/p/6985417.html
Copyright © 2011-2022 走看看