Operator is a symbol that tells the computer to perform the mathematical and logical operation in Python Programming.
Types of Operators:
Python programming language has supports the following operators.
- Arithmetic Operators
- Comparison / Relational Operators
- Logical Operators
- Assignment Operators
- Bitwise Operators
- Membership Operators
- Identity Operators
Arithmetic Operators in Python Programming
Let's Assume that variable 'a' holds 5 and variable 'b' holds 2, then
|Addition (+)||Adds values on either side of the operator.||a + b = 7|
|Subtraction (-)||Subtracts right hand operand from left hand operand.||a - b = 3|
|Mutliplication (*)||Multiplies values on either side of the operator.||
a * b = 10
|Division (/)||Divides one operator to another operator.||a / b = 2.5|
|Modulus (%)||remainder of a divided by b.||a % b = 1|
|Exponent (**)||Performs expontial (power) calculation on operators.||a**b = 25|
|//||Floor Division - operands where the result is the quotient in which the digits after the decimal point are removed.||a//b = 2|
Relation Operators in Python Programming
The Relational Operator are used to compare the values between variables. Relational Operators tabel below...
|==||If the both values are equal, then condition is true.||(a==b) is not true|
|!=||If the both values are not equal, then condition becomes true.||(a!=b) is true.|
|>||Greater Than ( if the left operand is greater than the right operand, then condition becomes true.)||(a > b) is true.|
|<||Less Than ( if the left operand is less than the right operand, then condition becomes true.)||(a<b) is true.|
|<=||Less than or Equal to||(a <= b ) is not true.|
|>=||Greater than or Equal to||(a >= b) is true.|
Assignment Operators in Python Programming.
The assignment operator is represented by the equal sign(=). The variable appearing on the left side of = sign and it is assignment the value appearing on the right side of this sign.
|=||a = a + b||a = 7|
|+=||a += b||a = a + b = 7|
|-=||a -= b||a = a - b = 3|
|/=||a /= b||a = a / b = 2.5|
|%=||a %= b||a = a % b = 1|
|*=||a *= b||a = a * b = 10|
|**=||a **=b||a = a**b = 25|
|//=||a //= b||a = a//b = 2|
Logical Operator in Python Programming.
The Logical Operator is used for when we want to check the condition and for making the decisons in Programs.
|and Logical AND||If the both operands are true then condition becomes true.||(a and b) is true.|
|or Logical OR||If any of the two operands are non-zero then condition becomes true.||(a or b) is true.|
|not Logical NOT||Used to reverse the logical state of its operand.||not(a and b) is false|
Bitwise Operator in Python Programming.
The Bitwise Operator is special operators which are used for manipulation of the data at bit level. These operator are used for testing the bits, or shifting them right or left. Bitwise operators many not be applied to float or double.
|^||bitwise exclusive OR|
Python Membership Operators.
Python's membership operators test for membership in a sequence, such as strings, lists, or tuples. The are two mebership operators...
|in||Evalutes to true if it finds a variable in the specified sequence and false otherwise.||a in b, here in results in a 1 if x is a member of sequence y.|
|not in||Evaluates to true if it does not finds a variable in the specified sequence and false otherwise.||a not in y, here not in results in 1 if a is not a member of sequence b.|
Python Identity Operators.
|is||Evaluates to true if the variables on either side of the operator point to the same object and false otherwise.||a is b, here is results false.|
|is not||Evaluates to false if the variables on either side of the operator point to the same object and true otherwise.||a is not b, here is not results is true.|
In Python It is called a string which is inside single or double quotation marks. We can write multiline string inside three single or double quotation mark.