V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
jakeyfly
V2EX  ›  问与答

**kw 字典传参问题

  •  
  •   jakeyfly · 2018-03-09 22:05:46 +08:00 · 1045 次点击
    这是一个创建于 2255 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    为啥报错呢

    2 条回复    2018-03-09 23:00:40 +08:00
    xgzxy
        1
    xgzxy  
       2018-03-09 22:50:04 +08:00
    """
    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  
       2018-03-09 23:00:40 +08:00
    dict(a,**b) = dict(a, **{'b': 'cc'}) = dict(a, b='cc') = {'a': 'bb', 'b': 'cc'}
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2497 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 01:48 · PVG 09:48 · LAX 18:48 · JFK 21:48
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.