Python operators are used to performing the operation between values and variables. Additionally, there are different types of operators use in a programming language. In this article, we will discuss these operators in detail by dividing them into different categories. Finally, in this article, you will learn about python operators from basic to advance.
The arithmetic operators use to calculate the mathematical operation between two operands. Additionally, these operations are addition, subtractions, multiplications and divisions. The following table depicts the syntax and description of these operators.
And following code the actual implementation in a Python programming language.
X=3 Y=2 print(X+Y) print(X-Y) print(X*Y) print(X/Y) print(X%Y) print(X**Y)
Output: 5 1 6 1.5 1 9
Comparison operations are the most useful operators it’s generally used for comparing two operands. Moreover, the most common comparison operators are greater than, less than, equals etc. The following table shows the syntax and description of these operands.
The output of the comparison operation obtains in the form of either True or False. The following code shows how to comparison operations use in a python programming language.
X=3 Y=2 print(X>Y) print(X<Y) print(X==Y) print(X!=Y) print(X>=Y) print(X<=Y)
Output: True False False True True False
There are three logical operators use in the python programming language. They are and, or and not. Further, the output of these operators is either True or False. The following table shows the syntax and description of these operands in detail.
The input variables of a logical operator are either True or False. The following code shows how logical operators are used in the python program.
X=True Y=False print(X&Y) print(X or Y) print( not X)
Output: False True False
Bitwise operators are also the most useful operators in a python programming language. These operators perform the operation bit by bit. Additionally, there are different types of bitwise operators are used in practice. The following table depicts the syntax and description of bitwise operators.
The following code shows the implementation of bitwise operators in a python programming language.
a=10 b=3 print(a&b) print(a|b) print(~a) print(a^b) print(a>> b) print(a<<b)
Output: 2 11 -11 9 1 80
On the other hand, assignment operators are used to assigning the value to the operand. There are different type of assign operators use in a programming language such as normal assignment, And add, And subtraction etc. following table show the syntax and description of different type of assignment operand in details.
These operators are used to check whether the value is present or not in a sequence of data. additionally, there is two types of membership operators are practised. In and not in are the type of membership operators. The output return by this operator is either True or False. The following table shows the syntax and description of membership operators in detail.
The following code shows how to use membership operators in a python programming language
X=[1,2,4,3,5] print(2 in X) print(6 not in X)
Output: True True
OK, this is the end of the article I hope you can get a good lesson from what I deliver in this article. I ask forgiveness for any word and behave which are not to be. Thank you for your kind and attention guys. Stay tuned for the next article. if you are searching for a free python course here is a link. If you have any questions regarding this article please feel free to comment below.