Operators

  1. Arithmetic Operators

  2. Comparison Operators

  3. Logical Operators

  4. Assignment Operators

  5. Binary Operators

  6. Identity Operators

  7. Membership Operators

Arithmetic Operators

  1. Addition Operator ( + )

  2. Subtraction Operator ( - )

  3. Multiplication Operator ( * )

  4. Division Operator ( / )

  5. Modulas Operator ( % )

  6. Floor Division ( // )

  7. Exponent Operator ( ** )

Example 1:

Addition of 10 and 3 is 13.

hello world

[4, 5, 6, 1, 2, 3]

('one', 'two', 'three', 'four', 'five', 'six')

Example 2:

-40

TypeError Traceback (most recent call last)

in () 8 l1 = [ 1,2,3] #list does not support subtraction operation 9 l2 = [ 4,5,6] ---> 10 print(l1-l2)

TypeError: unsupported operand type(s) for -: 'list' and 'list'

Example 3:

1060

Hello_World Hello_World Hello_World Hello_World Hello_World Hi Hi Hi

[1, 2, 3, 1, 2, 3, 1, 2, 3]

TypeError Traceback (most recent call last)

in () 11 print(l13) #returns list 3 times 12 l2 = [ 4,5,6] ---> 13 print(l1l2) # does not support multiplication

TypeError: can't multiply sequence by non-int of type 'list'

Example 4:

4.416666666666667

5

4

Example 5:

125

Comparison Operators

  1. Less Than ( < )

  2. Less Than Equals To ( <= )

  3. Greater Than ( > )

  4. Greater Than Equals To ( >= )

  5. Equals To Equals To ( == )

  6. Not Equals To ( != )

Example 6:

6 < 8 True

8 < 6 False

6 <= 6 True

6 <= 3 False

5 > 6 False

6 > 5 True

6 >= 6 True

6 >= 5 True

6 == 6 True

6 == 7 False

6 != 6 False

6 != 7 True

Logical Operators

  1. and

  2. or

  3. not

Negative/Positive integers are true, 0 is false

And

If x is false, return x

else return y

Eg:

False

-3

0

0

0

Or

If x is false, return y

else x

Example 7:

False

True

True

0

10

False

Example 8:

X Y and or

True True True True

True False False True

False True False True

False False False False

Example 9:

X not

True False

False True

Assignment Operators

Example 10:

something

Example 11:

14.0

Example 12:

13

8 7 hi hello how are you

Example 13:

6 5

10 -2 60

Membership Operator

Example 14:

Pattern Found in step 1

True

False

Example 15:

l2 found in l1

Example 16:

Enter a number : 324

Number matched

Identity Operator

Example 17:

True

False

Both are different

Last updated

Was this helpful?