zoukankan      html  css  js  c++  java
  • python--参数列表的分拆

      当你要传递的参数已经是一个列表,调用的函数却接受分开一个个的参数,这个时候可以考虑参数列表拆分:

    • 可以使用* 操作符来自动把参数列表拆开:
    args=[3,6]
    x=list(range(*args))
    print x

    -------------------输出-----------------------------

    [3, 4, 5]

    • 可以使用 ** 操作符分拆关键字参数为字典:
    def parrot(voltage,state='a stiff',action='voom'):
        print "-- This parrot wouldn't ",action,
        print "if you put ",voltage,"volts through it.",
        print "E's",state,"!"
        
    d={"voltage":"four million", "state":"bleedin demised","action":"voom"}
    
    parrot(**d)


    -------------------输出-----------------------------

    -- This parrot wouldn't  voom if you put  four million volts through it. E's bleedin demised !
  • 相关阅读:
    单调队列
    Johnson全源最短路
    重链剖分
    矩阵快速幂
    Tarjan
    题解 UVA439 骑士的移动 Knight Moves
    题解 SP10500 HAYBALE
    题解 P4058 [Code+#1]木材
    题解 P3395 路障
    题解 SP24 FCTRL2
  • 原文地址:https://www.cnblogs.com/nzyjlr/p/4704044.html
Copyright © 2011-2022 走看看