30
loading...
This website collects cookies to deliver better user experience
Operator | Description | Syntax |
+ | Addition: It adds two operands | x + y |
- | Subtraction: It subtracts two operands | x - y |
* | Multiplication: It multiplies two operands | x * y |
/ | Division (float): It divides the first operand by the second | x / y |
// | Division (floor): It divides the first operand by the second | x // y |
% | Modulus: It returns the remainder when the first operand is divided by the second | x % y |
** | Power: It Returns first raised to power second | x ** y |
# Examples of Arithmetic Operator
a = 90
b = 40
# Addition of numbers
add = a + b
# Subtraction of numbers
sub = a - b
# Multiplication of number
mul = a * b
# Division(float) of number
div1 = a / b
# Division(floor) of number
div2 = a // b
# Modulo of both number
mod = a % b
# Power
p = a ** b
# print results
print(add)
print(sub)
print(mul)
print(div1)
print(div2)
print(mod)
print(p)
Output:
130
50
3600
2.25
2
1
1.4780E + 78
Operator | Description | Syntax |
> | Greater than: It gives True if the left operand is greater than the right | x > y |
< | Less than: It gives True if the left operand is less than the right | x < y |
== | Equal to: It gives True if both operands are equal | x == y |
!= | Not equal to: It gives True if operands are not equal | x != y |
>= | Greater than or equal to : It gives True if the left operand is greater than or equal to the right | x >= y |
<= | Less than or equal to : It gives True if the left operand is less than or equal to the right | x <= y |
# Examples of Relational Operators
a = 1
b = 3
# a > b is False
print(a > b)
# a < b is True
print(a < b)
# a == b is False
print(a == b)
# a != b is True
print(a != b)
# a >= b is False
print(a >= b)
# a <= b is True
print(a <= b)
Output:
False
True
False
True
False
True
Operator | Description | Syntax |
And | Logical AND: It gives True if both the operands are true | x and y |
Or | Logical OR: It gives True if either of the operands is true | x or y |
Not | Logical NOT: It gives True if the operand is false | not x |
# Examples of Logical Operator
a = True
b = False
# Print a and b is False
print(a and b)
# Print a or b is True
print(a or b)
# Print, not a is False
print(not a)
Output:
False
True
False
Operator | Description | Syntax |
& | Bitwise AND | x & y |
| | Bitwise OR | x | y |
~ | Bitwise NOT | ~x |
^ | Bitwise XOR | x ^ y |
>> | Bitwise right shift | x>> |
<< | Bitwise left shift | x<< |
# Examples of Bitwise operators
a = 10
b = 4
# Print bitwise AND operation
print(a & b)
# Print bitwise OR operation
print(a | b)
# Print bitwise NOT operation
print(~a)
# print bitwise XOR operation
print(a ^ b)
# print bitwise right shift operation
print(a >> 2)
# print bitwise left shift operation
print(a << 2)
Output:
0
14
-11
14
2
40
Operator | Description | Syntax |
= | Assign the value of the right side of expression to the left side operand | x = y + z |
+= | Add AND: Add right-side operand with left side operand and then assign to left operand | a+=b a=a+b |
-= | Subtract AND: Subtract right operand from left operand and then assign to left operand | a-=b a=a-b |
*= | Multiply AND: Multiply right operand with left operand and then assign to left operand | a*=b a=a*b |
/= | Divide AND: Divide left operand with right operand and then assign to left operand | a/=b a=a/b |
%= | Modulus AND: Takes modulus using left and right operands and assign the result to left operand | a%=b a=a%b |
//= | Divide(floor) AND: Divide left operand with right operand and then assign the value(floor) to left operand | a//=b a=a//b |
**= | Exponent AND: Calculate exponent(raise power) value using operands and assign value to left operand | a**=b a=a**b |
&= | Performs Bitwise AND on operands and assign value to left operand | a&=b a=a&b |
|= | Performs Bitwise OR on operands and assign value to left operand | a|=b a=a|b |
^= | Performs Bitwise XOR on operands and assign value to left operand | a^=b a=a^b |
>>= | Performs Bitwise right shift on operands and assign value to left operand | a>>=b a=a>>b |
<<= | Performs Bitwise left shift on operands and assign value to left operand | a <<= b a= a << b |