这看起来非常冗长,特别是对于长函数名称,有没有更好的方法在Python中执行此操作?
if someRandomFunction():
variable = someRandomFunction()
Run Code Online (Sandbox Code Playgroud)
编辑:对于更多上下文变量尚未定义,它将是树上的新节点.如果someRandomFunction()返回一个值,我只想创建这个节点.而someRandomFunction()应该从不同类型的树返回某个节点的字符串表示.
Gre*_*ill 14
您可以...吗:
variable = someRandomFunction() or variable
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅Python文档中的布尔运算.