[Python] Object spread operator in Python

In JS, we have object spread opreator:

const x = {
     a: '1', b: '2'
}

const y = {
  c: '3', d: '4'
}

const z = {
   ...x,
   ...y
}

// z = {a: '1', b: '2', c: '3', d: '4'}

 

In python we can do:

x = {'a': 1, 'b': 2}
y = {'b': 3, 'c': 4}

z = {**x, **y}

// z= {'c': 4, 'a': 1, 'b': 3}

 

posted @ 2017-09-26 16:25  Zhentiw  阅读(203)  评论(0编辑  收藏  举报