Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
This article was originally published on Medium
Follow me:
Logical Operators
Rust logical operator symbols are different from Python ones.
Meaning | Python | Rust |
---|---|---|
True if both the operands are true | and | && |
True if either of the operands is true | or | || |
True if operand is false | not | ! |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
fn main() {
let a = true;
let b = false;
let c = !a;
let d = a && b;
let e = a || b;
println!("
a: {}, b: {},
c: !{0} is {},
d: {0} && {1} is {},
e: {0} || {1} is {}",
a, b, c, d, e);
}
Enter to Rename, Shift+Enter to Preview
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content