What are the different types of operator used in python? Explain with examples
Answers
Python operator is a symbol that performs an operation on one or more operands. An operand is a variable or a value on which we perform the operation.
Python Operator falls into 7 categories:
Python Arithmetic Operator
Python Relational Operator
Python Assignment Operator
Python Logical Operator
Python Membership Operator
Python Identity Operator
Python Bitwise Operator
There are mainly 4 types of operators in Python.
- Arithmetic Operators
- Relational Operators
- Logical Operators
- Assignment Operators
1. Arithmetic operators
Arithmetic operators, as the name suggests, are operators that deal with calculations/algebraic expression. They include addition [+], subtraction [-], multiplication [*], division [/], exponentiation [**], modulo [%] and floor division [//].
2. Relational operators
Relational operators are used to compare two values that may result to either True or False. They include less than [<], greater than [>], less than/equal to [<=], greater than/equal to [>=], not equal to [!=] and equal to [=].
3. Logical operators
Logical operators are used to compare two expressions/values, somewhat similar to relational operators. They include and, or and not.
4. Assignment operators
Assignment operators are used to assign values into variables. They include =, +=, -=, /=, %=, **= and //=.