@ -3,7 +3,7 @@ title: Basic Operators
|
||||
---
|
||||
## Basic Operators
|
||||
|
||||
Operators are symbols which tells the interpreter to do a specific operation (viz arithmetic, comparison, logical, etc.)
|
||||
Operators are symbols that tell the interpreter to do a specific operation (e.g. arithmetic, comparison, logical, etc.)
|
||||
|
||||
The different types of operators in Python are listed below:
|
||||
|
||||
@ -19,7 +19,7 @@ The different types of operators in Python are listed below:
|
||||
|
||||
An arithmetic operator takes two operands as input, performs a calculation and returns the result.
|
||||
|
||||
Consider the expression, <b>“a = 2 + 3”</b>. Here, `2` and `3` are the <i>operands</i> and `+` is the <i>arithmetic operator</i>. The result of the operation is stored in the variable a.
|
||||
Consider the expression, <b>“a = 2 + 3”</b>. Here, `2` and `3` are the <i>operands</i> and `+` is the <i>arithmetic operator</i>. The result of the operation is stored in the variable a. (This is because `=` is an assignment operator. See below.)
|
||||
|
||||
<table style="width:100%">
|
||||
<tr>
|
||||
@ -69,11 +69,11 @@ Consider the expression, <b>“a = 2 + 3”</b>. Here, `2` and `3` are the <i>op
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
Note: To get the result in floating type, one of the operands must also be of float type.
|
||||
Note: To get the result as floating type, one of the operands must also be of float type.
|
||||
|
||||
#### Comparison (Relational) Operators
|
||||
|
||||
A comparison or relational operator is used to compare two operands to decide a relation between them. It returns a boolean value based on the condition.
|
||||
A comparison or relational operator is used to compare two operands to determine the relationship between them. It returns a boolean value based on the condition.
|
||||
|
||||
<table style="width:100%">
|
||||
<tr>
|
||||
@ -115,9 +115,9 @@ A comparison or relational operator is used to compare two operands to decide a
|
||||
|
||||
#### Bitwise Operators
|
||||
|
||||
A bitwise operator performs operations on the operands bit by bit
|
||||
A bitwise operator performs operations on the operands bit by bit.
|
||||
|
||||
Consider a = 2 (in binary notation, 10) and b = 3 (in binary notation, 11) for the below usages
|
||||
Consider a = 2 (in binary notation, 10) and b = 3 (in binary notation, 11) for the below usages.
|
||||
|
||||
<table style="width:100%">
|
||||
<tr>
|
||||
@ -159,7 +159,7 @@ Consider a = 2 (in binary notation, 10) and b = 3 (in binary notation, 11) for t
|
||||
|
||||
|
||||
#### Assignment Operators
|
||||
An assignment operator is used to assign values to a variable. This is usually combined with other operators (like arithmetic, bitwise) where the operation is performed on the operands and the result is assigned to the left operand.
|
||||
An assignment operator is used to assign values to a variable. This is usually combined with other operators (like arithmetic, bitwise, etc.) where the operation is performed on the operands and the result is assigned to the left operand.
|
||||
|
||||
Consider the following examples,
|
||||
<br>
|
||||
@ -257,7 +257,7 @@ A logical operator is used to make a decision based on multiple conditions. The
|
||||
|
||||
#### Membership Operators
|
||||
|
||||
A membership operator is used to identify membership in any sequence (lists, strings, tuples).
|
||||
A membership operator is used to identify membership in any sequence (e.g. lists, strings, tuples).
|
||||
<br>`in` and `not in` are membership operators
|
||||
|
||||
<br>`in` returns True if the specified value is found in the sequence. Returns False otherwise.
|
||||
@ -292,7 +292,7 @@ An identity operator is used to check if two variables share the same memory loc
|
||||
<br>`is` returns True if the operands refer to the same object. Returns False otherwise.
|
||||
<br>`is not` returns True if the operands do not refer to the same object. Returns False otherwise.
|
||||
|
||||
Please note that two values when equal, need not imply they are identical.
|
||||
Please note that two values being equal does not necessarily require they be identical.
|
||||
|
||||
###### Example Usage
|
||||
|
||||
|
Reference in New Issue
Block a user