Python Not Operator
If you're not sure about the answers, you can always just execute the program to see the results. I've done so in Java just for peace of mind and will explain each of the tests. For simplicity in Java I've just put the result of the exponent parts.
public class Test {
public static void main(String[] args) {
boolean test[] = new boolean[5];
test[0] = !true;
test[1] = !(81 < 64);
test[2] = !(10 % 3 <= 10 % 2);
test[3] = !((9 + 16) != 25);
test[4] = !!false;
for (boolean b : test) {
System.out.println(b);
}
// results:
// 1. false
// 2. true
// 3. true
// 4. true
// 5. false
}
}
1. not True: not (or ! in Java) just means the opposite of whatever the result is, so False.
2. not (81 < 64): 81 is NOT less than 64, so that expression results in False. So not False is True.
3. not (10 % 3 <= 10 % 2): 10 mod 3 = 1, 10 mod 2 = 0. So 1 <= 0 is False, and not False is True.
4. not ((9 + 16) != 25): 9 + 16 = 25 != 25. Well 25 IS equal to 25, so the expression is False, and not False is True.
5. not not False: again, think of it like this: not (not False) = not True = False.
Feel free to ask if any of this is unclear.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now