Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents


Basic Operators

Python Arithmetic Operators

OperatorDescriptionExample
+ AdditionAdds values on either side of the operator.10 + 20 = 30
- SubtractionSubtracts right hand operand from left hand operand.10 – 20 = -10
* MultiplicationMultiplies values on either side of the operator10 * 20 = 200
/ DivisionDivides left hand operand by right hand operand20 / 10 = 2
% ModulusDivides left hand operand by right hand operand and returns remainder20 % 10 = 0
** ExponentPerforms exponential (power) calculation on operators10**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


OperatorDescriptionExample
==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

...