首页 > 解决方案 > How to concatenate arrays using conditioning in Python?

问题描述

I have arrays 'a', 'b' and 'c'. I want to create the array 'd' using concatenate() and add a, b or c if they exist.

d = concatenate([a (if a exists),b (if b exists),c (if c exists)])

标签: pythonconcatenation

解决方案


通常,即使变量为空,您也会存在所有变量,因此在您决定是否创建变量的其他代码中,将其初始化为 [],然后再做出是否将值放入其中的正常决定与否,我相信这是 Python 的标准做法

这意味着连接将起作用


推荐阅读