zoukankan      html  css  js  c++  java
  • 关于函数可变参数

     1 def test(a, b, c, d):
     2     print a, b, c, d
     3     return "->".join([str(a), str(b), str(c), str(d)])
     4 
     5 def test1(a, b, c, d):
     6     print a, b, c, d
     7     return "->".join([str(a), str(b), str(c), str(d)])
     8 
     9 
    10 def test2(*args, **kwargs):
    11     print "args: " + str(args)
    12     print "kwargs: " + str(kwargs)
    13 
    14 def main():
    15     param = [1,2,3,4]
    16     param1 = {
    17         "a":1,
    18         "b":2,
    19         "c":3,
    20         "d":4,
    21     }
    22     
    23     print test(*param)
    24     print test1(**param1)
    25     print test2(*param, **param1)
    26 
    27 if __name__ == '__main__':
    28     main()
    test_args.py
    1 2 3 4
    1->2->3->4
    1 2 3 4
    1->2->3->4
    args: (1, 2, 3, 4)
    kwargs: {'a': 1, 'c': 3, 'b': 2, 'd': 4}
    None
    

      

  • 相关阅读:
    比较全的笔记
    ios路线
    字符串颜色
    ios 开发学习步骤
    百度地图反地理
    p12证书
    ios官方demo
    ios视频网盘
    图片穿透
    OC温习一:基本数据类型
  • 原文地址:https://www.cnblogs.com/huaizhi/p/8376562.html
Copyright © 2011-2022 走看看