Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejava
titleLogical Operators in Java
boolean x = true;
boolean y = false;

// Output: x and y is false
System.out.println("x and y is " + (x && y));

// Output: x or y is true
System.out.println("x or y is " + (x || y));

// Output: not x is false
System.out.println("not x is " + !x);
Code Block
languagepy
titleLogical Operators in Python
x = True
y = False

# Output: x and y is False
print('x and y is',x and y)

# Output: x or y is True
print('x or y is',x or y)

# Output: not x is False
print('not x is',not x)

 

Negation is also formed differently between those two programming languages.

Code Block
languagejava
titleOperators in Java
 ! (x > 0 && y > 0) || z > 0 ^ w > 0
Code Block
languagepy
titleOperators in Python
not(x > 0 and y > 0) or z > 0

...