Operators in Python.
Operator:
Operators are special symbol in python that carry out arithmatic or logical computation, Used to perform specific operation.
For Example:
Types of Operator:
Arithmatic operator:
Arithmatic operators are used to perform mathematical operation like addition,subtraction ,multiplication etc.
Addition(+):
Adds value on either of the operators.
Example:
Output:
Subtraction(-):
Subtracts right hand operands form left hand oprand.
Example:
Output:
Multiplication(*):
Multiply values on either side of the operators.
Example:
Output:
Division(/):
divides left hand operand by right hand operand.
Example:
Output:
Module(%):
Divides left hand operand by right hand operand and returns remainder.
Example:
Output:
Assignment operators:
Assignment operators are used in python to assign values to variables.
=,+=,-=,*=,/=,%=
Example:
Output:
Comparison operators:
Comparision operators are used to compare values. It either returns True or False accoriding to the condition.
Grater than(>):
x>y
it gives True if left operand is grater than the right.
Example:
Output:
Less than(<):
x < y
it gives True if left operand is grater than the right.
Example:
Output:
Equal to(==):
x==y
True if both operands is equal.
Example:
Output:
Not equal to(!=):
x!=y
True if operands are not equal.
Example:
Output:
Grater than or equal to(>=):
x>=y
True if left operand is grater than or equal to the right.
Example:
Output:
Grater than or equal to(>=):
x>=y
True if left operand is grater than or equal to the right.
Example:
Output:
Less than or equal to (<=):
x= True if right operand is grater than or equal to the right. Example: Output: Logical operator are the and,or,not operators. True if both the operands are true. x and y Example: Output: True if either of the operands is true. x or y Example: Output: True if operand is false (complements of the operand). not y Example: Output: Bitwise operator works on bits and perform bit by bit operation. Example: Output: Example: Output: Example: Output: Example: Output: Example: Output: Example: Output: 'is' and 'is not' are the identity operators in python. They are check if two values (or variables) are located on the same part of memory .
Two variables that are equal does not imply that they are identical. True if the variable on either side of the operator point to the same object and false otherwise. Example: Output: false if the variables on either side of the operator point to the same object and true otherwise.. Example: Output: 'in' and 'not in' are the membership operator in python. True if the finds a variable in the specified sequence and false otherwise. Example: Output: True if it does not finds a variable in the specified sequence and false otherwise. Example: Output:logical Operator:
AND
OR
NOT:
Bitwise operators:
Bitwise AND(&):
Bitwise OR(|):
Bitwise NOT(~):
Bitwise XOR(^):
Bitwise right shift(>>):
Bitwise left shift (<<):
Indentity operator:
IS:
IS NOT:
Membership operator:
IN:
NOT IN:
Comments
Post a Comment