我想在Python3中使用铁锈火柴
而不是if…elif语句。你知道吗
https://doc.rust-lang.org/rust-by-example/flow_control/match.html
fn main() {
let number = 13;
// TODO ^ Try different values for `number`
println!("Tell me about {}", number);
match number {
// Match a single value
1 => println!("One!"),
// Match several values
2 | 3 | 5 | 7 | 11 => println!("This is a prime"),
// Match an inclusive range
13...19 => println!("A teen"),
// Handle the rest of cases
_ => println!("Ain't special"),
}
let boolean = true;
// Match is an expression too
let binary = match boolean {
// The arms of a match must cover all the possible values
false => 0,
true => 1,
// TODO ^ Try commenting out one of these arms
};
println!("{} -> {}", boolean, binary);
}
谢谢你的提示,安德里亚·科尔贝里尼。你知道吗
我找到了解决方案,有pampy
相关问题 更多 >
编程相关推荐