Use Of Operators In Python Language

Watch video presentation and remember to subscribe to our channel;

Watch now!
In this tutorial we will discuss use of operators in Python. As we have been discussing in other programming languages, we will discuss various types of operators used in python giving out the relevant examples, there are multiple types of operators which may include;
  • Comparison operators
  • Logical operators
  • Arithmetic operators
  • Bitwise operators
  • Assignment operators
  • Identity operators
In the following section we will be explaining each type of operators giving out examples in various cases for better understanding;

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(!=)
let’s have an example here for better understanding;
    
        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(**)
Let’s have an example here for better understanding;
    
  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(//=)
Let’s have examples here for better understanding;
    
        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.
Let’s have an example here for better understanding;
    
        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
Thanks for reading through our tutorial, hope now you understand various types of operators in python, as we continue learning about python hoping to meet you in our next tutorial.