以下Python代码返回的第一个非空字符串(在本例中,bar
内容):如何返回第一个非空字符串?
foo = ""
bar = "hello"
foo or bar # returns "hello"
我怎样写它的锈?我试着用这样的:
let foo = "";
let bar = "";
foo || bar;
,但我得到这个
error[E0308]: mismatched types
--> src/main.rs:4:5
|
4 | foo || bar;
| ^^^ expected bool, found &str
|
= note: expected type `bool`
found type `&str`
我想我不能轻易做什么,我在Python做锈?
python代码到底做了什么? –
你为什么不直接连接字符串? – fancyPants
@JanNilsFerner它返回第一个非空字符串(在本例中'bar'的内容) @fancyPants,因为有时'foo'可能已经被填充,并且我想在'foo'中返回内容而不是 – Jeffrey04