问题1
在rust中,我可以编写如下代码:
let foo = if ... {
1
} else if ... {
2
} else {
3
};
这里,foo被分配了if-elseif-else表达式的返回值
类似的东西在Python中可能吗
问题2
这个python代码中的外部变量“foo”更新了吗
foo = "hello"
if cond1:
foo = "world"
else:
pass
# if cond1 is true, what is the value of foo now? "hello" or "world"
看起来最接近的Py版本是三元op
相关问题 更多 >
编程相关推荐