Watch video presentation and remember to subscribe to our channel;
- Comparison operators
- Logical operators
- Arithmetic operators
- Bitwise operators
- Assignment operators
- Identity operators
1. Comparison operators
These type of operators are used to compare two variables or values, they may include;- Equal(==)
- Great than(>)
- Greater than or equal to(>=)
- Not equal(!=)
case 1;
x = 5
y = 6
if x == y:
print("The two numbers are equal")
else:
print("The two numbers are not equal")
Case 2;
x = 7
y = 8
if x > y:
print("This is true")
else:
print("This is false")
#You may try it using a different comparison operator and values
2. Arithmetic operators
These types of operators are used to perform common mathematical operations they may include;- Addition(+)
- Subtraction(-)
- Multiplication(*)
- Division(/)
- Modulus(%)
- Exponentiatian(**)
Case 1;
x = 5
y = 6
print(x+y)
Case 2;
x = 10
y = 20
print(x/y)
#You may use a different Arithmetic operator and values
3. Assignment operator
These types of operators are used assig values to the variables, they may include;- Add and assign(+=)
- Subtract and assign(-=)
- Multiply and assign(*=)
- Divide and assign(/=)
- Remainder assignment(%=)
- Float division assignment(/=)
- Integer division assignment(//=)
Case 1;
print(x += 7)
It will produce; x = x + 7
Case 2;
print(x //= 7)
It will produce; x = x // 7
Case 1;
print(x %= 8)
It will produce; x = x %= 8
#You may try it using different assignment operator and values
4. Logical operators
These kind of operators are used to combine various conditional statements, they may include;- and -this operator returns true if the two expression are true
- or -this operator returns true if one of the expression gives out true
- not -this type of logical operator reverses the result, for instance it will return true if the result is false.
Case 1;
x = 11
y = 9
print(x > y and x != y)
#It will produce true
Case 2;
x = 13
y = 12
print not(x > y and x != y)
#It will produce false
5. Identity operators
These operators compares objects are the same, have same location and the same memory location, they are only two that is; is, is not- is -This operator returns true if both variables are of the same object
- is not -This operator returns true if both the variables are not of the same object