V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
jakeyfly
V2EX  ›  问与答

**kw 字典传参问题

  •  
  •   jakeyfly · Mar 9, 2018 · 1435 views
    This topic created in 2975 days ago, the information mentioned may be changed or developed.

    a = {'a':'bb'} b = {'b':'cc'} dict(a,**b) 不会报错

    dict(a,{'b':'cc'})

    为啥报错呢

    2 replies    2018-03-09 23:00:40 +08:00
    xgzxy
        1
    xgzxy  
       Mar 9, 2018
    """
    dict() -> new empty dictionary
    dict(mapping) -> new dictionary initialized from a mapping object's
    (key, value) pairs
    dict(iterable) -> new dictionary initialized as if via:
    d = {}
    for k, v in iterable:
    d[k] = v
    dict(**kwargs) -> new dictionary initialized with the name=value pairs
    in the keyword argument list. For example: dict(one=1, two=2)
    # (copied from class doc)
    """
    SingeeKing
        2
    SingeeKing  
    PRO
       Mar 9, 2018
    dict(a,**b) = dict(a, **{'b': 'cc'}) = dict(a, b='cc') = {'a': 'bb', 'b': 'cc'}
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2592 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 06:13 · PVG 14:13 · LAX 23:13 · JFK 02:13
    ♥ Do have faith in what you're doing.