Table of Contents |
---|
Basic Operators
Python Arithmetic Operators
Operator | Description | Example |
---|---|---|
+ Addition | Adds values on either side of the operator. | 10 + 20 = 30 |
- Subtraction | Subtracts right hand operand from left hand operand. | 10 – 20 = -10 |
* Multiplication | Multiplies values on either side of the operator | 10 * 20 = 200 |
/ Division | Divides left hand operand by right hand operand | 20 / 10 = 2 |
% Modulus | Divides left hand operand by right hand operand and returns remainder | 20 % 10 = 0 |
** Exponent | Performs exponential (power) calculation on operators | 10**20 =10 to the power 20 |
// | Floor Division - The division of operands where the result is the quotient in which the digits after the decimal point are removed. But if one of the operands is negative, the result is floored, i.e., rounded away from zero (towards negative infinity) − | 9//2 = 4 and 9.0//2.0 = 4.0 -11//3 = -4 -11.0//3 = -4.0 |
Python Comparison Operators
Info |
---|
Below example is based on the condition as a=10, b=20 |
Operator | Description | Example |
---|---|---|
== | If the values of two operands are equal, then the condition becomes true. | (a == b) is not true. |
!= | If values of two operands are not equal, then condition becomes true. | (a != b) is true. |
<> | If values of two operands are not equal, then condition becomes true. | (a <> b) is true. This is similar to != operator. |
> | If the value of left operand is greater than the value of right operand, then condition becomes true. | (a > b) is not true. |
< | If the value of left operand is less than the value of right operand, then condition becomes true. | (a < b) is true. |
>= | If the value of left operand is greater than or equal to the value of right operand, then condition becomes true. | (a >= b) is not true. |
<= | If the value of left operand is less than or equal to the value of right operand, then condition becomes true. | (a <= b) is true. |
Data Structures - List / Set / Tuple / Dictionary
...
The result will be like below
Result |
---|
{'Seoul', 'Incheon'} {'Seoul', 'Incheon'} |
Find different elements from two arrays based on "symmetric_difference" method
...
The result will be like below
Result |
---|
{'Jake', 'Eric', 'Jill'} {'Eric', 'Jake', 'Jill'} |
Find different elements from two arrays based on "difference" method
...
The result will be like below
Result |
---|
{'Jake', 'Eric'} {'Jill'} |
Find different elements from two arrays based on "union" method
...
The result will be like below
Result |
---|
{'John', 'Eric', 'Jake', 'Jill'} |
Print out a set containing all the participants from event A which did not attend event B
...