...
Code Block |
---|
language | java |
---|
title | Strings Operators in Java |
---|
| ! (x > 0 && y > 0) || z > 0 ^ w > 0 |
| Code Block |
---|
language | py |
---|
title | Operators in Python |
---|
| not(x > 0 and y > 0) or z > 0 |
|
The comparison operator for numbers are the same as in Python. For built-in types, instead of == in Python, Java uses equals method.
In In Java, most of the comparison operators ( >, <, >=, and <=) can be applied only to primitive types, while in Python, the comparison operators can be applied to numbers, strings, and other types of objects, and compare values in some appropriate way (e.g. numeric order, lexical order) where possible.. Two (== and !=) can be applied to any object, but when applied to reference types they test for same (different) object rather than same (different) value.
Code Block |
---|
language | java |
---|
title | Strings in Java |
---|
| |
| Code Block |
---|
language | py |
---|
title | Strings in Python | Logical 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 |
---|
language | java |
---|
title | Negation in Java |
---|
| int x = 10;
int y = 12;
// Output: x > y is false
System.out.println("x > y is " + (x>y));
// Output: x < y is true
System.out.println("x < y is " + (x<y));
// Output: x == y is false
System.out.println("x == y is " + (x==y));
// Output: x != y is true
System.out.println("x != y is " + (x!=y));
// Output: x >= y is false
System.out.println("x >= y is " + (x>=y));
// Output: x <= y is true
System.out.println("x <= y is " + (x<=y)); |
| Code Block |
---|
language | py |
---|
title | Negation Comparison operators in Python |
---|
| x = 10
y = 12
# Output: x > y is not y False
print('x > y is',x>y)
# Output: x < y is True
print('x < y is',x<y)
# Output: x == y is False
print('x == y is',x==y)
# Output: x != y is True
print('x != y is',x!=y)
# Output: x >= y is False
print('x >= y is',x>=y)
# Output: x <= y is True
print('x <= y is',x<=y) |
|