Python function composition

北慕城南 提交于 2019-12-03 01:13:30
martineau

append does in-place addition, as Ignacio Vazquez-Abrams said (well, implied) -- so, while you could fix that by just adding a return to your function, it would have the side-effect of changing the argument it was passed, too:

@composable
def f4(a):
    a.append(0)
    return a

It would be best to use the following even more concise code which also creates and returns a new object:

@composable
def f4(a):
  return a + [0]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!