Operator is nothing but perform the operation on operands.
There are several operators are there those are:
- Arithmetic operator
- Relational operator
- Logical operator
- Assignment operator
- Special operator
- Concatenation Operator
- Replication Operator
- Ternary Operator
- Special Operator
Arithmetic operator:
Addition | Subtraction |
Multiplication | Division and Floor Division |
Modulo Division | Exponent |
- Addition Operator: Addition operator denoted by “+”
- Subtraction Operator: Subtraction Operator denoted by “-”
- Multiplication Operator: Multiplication operator denoted by “*”
- Division Operator: Division operator denoted by “/”
- NOTE: Division operator give in float value’s.
- Modulo Operator: Modulo operator denoted by “%”
- Floor Division Operator: Floor division operator denotes by “//”
- Note: It will generate int or float depends on value’s.
- Exponent Operator: Exponent operator denotes by “**”
Relational operator: Relational operator also know as comparison operator.
> | >= | < |
<= | == | != |
- Less Than Operator: Less than operator denotes by “<“
- Less Than equal to Operator: Less than equal to operator denotes by “<=”
- Greater Than Operator: Greater than operator denotes by “>”
- Greater Than equal to Operator: Greater than equal to operator denotes by “>=”
- Equality Operator: equality operator denotes by “==”
- Not Equality Operator: Not equality operator denotes by “!=”
Logical Operator: Logical operator contains three operator’s. those are
- Logical And Operator
- Logical OR Operator
- Logical NOT Operator
- Logical And Operator: Returns true if both statements are true
- True and True = True
- Logical OR Operator: Returns true if one of the statements is true.
- True or False = True
- Logical NOT Operator: Reverse the result, returns false if the result is true.
- not True = False
Assignment Operator: Assignment operators are used to assign values to variables.
Concatenation Operator:
- “stackorigin” + 3 => can only concatenate str (not int) to str
- If we want apply “+” operator for string compalosory both arguments should be string only
- “stackorigin”+”tutorials” => “stackorigintutorials”
Replication Operator:
- If we want apply “*” operator compulsory one arguments should be string and another one is int.
- “Stackorigin” * 2 = StackoriginStackorigin
Ternary Operator: If condition true firstvalue will get or else secondvalue
- Syntax: firstvalue if condition else secondvalue
- example: x = 30 if 10<20 else 40
Special Operator: It contain two operator’s.
- Identity Operator
- Membership Operator
Identity Operator
Membership Operator: