Python Operators(contd)-6(b)

Let us continue the discussion with Python Assignment Operators

Everything that has been shared on the blogs must be noted in the register regularly.

Please read the description and example carefully
Assume variable a holds 10 and variable b holds 20, then −
 a+=2 is using the shorthand operator. Normal assignment would be a=a+2. So, "+=" is the shorthand operator. 

Operator
Description
Example
=
Assigns values from right side operands to left side operand
c = a + b assigns value of   a + b into c
+= Add AND
It adds right operand to the left operand and assign the result to left operand
c += a is equivalent to c = c + a
-= Subtract AND
It subtracts right operand from the left operand and assign the result to left operand
c -= a is equivalent to c = c - a
*= Multiply AND
It multiplies right operand with the left operand and assign the result to left operand
c *= a is equivalent to c = c * a
/= Divide AND
It divides left operand with the right operand and assign the result to left operand
c /= a is equivalent to c = c / a
%= Modulus AND
It takes modulus using two operands and assign the result to left operand
c %= a is equivalent to c = c % a
**= Exponent AND
Performs exponential (power) calculation on operators and assign value to the left operand
c **= a is equivalent to c = c ** a
//= Floor Division
It performs floor division on operators and assign value to the left operand
c //= a is equivalent to c = c // a


  • The assignment operators are used frequently when we are doing programming. 
  • New values are created using assignment operators, taking the inputs from the user.
  • Assignment statements will use variables and constants as "OPERANDS" and arithmetic operators(+,-,*,/,// or %) as  "OPERATORS"

Python Comparison Operators

  • These operators compare the values on either sides of them and decide the relation among them
  • They are also called Relational operators.
Assume variable a holds 10 and variable b holds 20, then −

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.


Example #2: Comparison operators in Python

x = 10
y = 12

# Output: x > y is False
print('x > y  is',x>y)

# Output: x < y is True
print('x < y  is',x<y)

# Output: x == y is False
print('x == y is',x==y)

# Output: x != y is True
print('x != y is',x!=y)

# Output: x >= y is False
print('x >= y is',x>=y)

# Output: x <= y is True
print('x <= y is',x<=y)
EXERCISE (Home Work)
  1. Write detailed notes on:-
    • arithmetic operators
    • assignment operators
    • comparison operators
  2. How is "=" different from "= =" operators?
  3. Differentiate between "/", "//" and the "%" operators.
  4. Differentiate between "< >" and " !=".
  5. What are shorthand operators? Give examples.
  6. What would be the result of
    • an arithmatic expression
    • a comparison

Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. Not assignment but the Comparison/Relational Operators. Sorry

    ReplyDelete
  3. We will begin the zoom session at 11 am. Kindly finish reading this concept before that

    ReplyDelete
  4. Pls understand the concept and note it down in the register. HW given at the end has to be done today. Submission tom

    ReplyDelete
  5. Good mornig mam
    Ashish- present

    ReplyDelete
  6. There is some technical issue with zoom. Trying to connect back. Pls wait

    ReplyDelete
  7. Lets come back to blog for discussion

    ReplyDelete
  8. Geet you had a question. Pls share

    ReplyDelete
  9. Ma'am, you told us to copy all the work given in the blog but we've already written about ASSIGNMENT OPERATORS & COMPARISION OPERATORS in our registers. So do we have to copy it down again? Please advise.....
    -Geet

    ReplyDelete
    Replies
    1. Beta some had missed the session and some others who didnt write. If u have, no need to repeat

      Delete
  10. One Zoom class is of 40 minutes. Rest of the discussion on Blog pls

    ReplyDelete
  11. Is there any difference between < > and !=

    ReplyDelete
  12. Is there any difference between < > and !=? Pls answer

    ReplyDelete
    Replies
    1. < the refers to if the right value is greater than the the left the condition is true
      > This refers if the left value is greater than the right the condition is true
      != This refers to if the both of the values are equal the condition is true

      Delete
    2. Yes mam there is a difference

      Delete
  13. Ma'am, you told us to copy all the work given in the blog but we've already written about ASSIGNMENT OPERATORS & COMPARISION OPERATORS in our registers. So do we have to copy it down again? Please advise.....
    -Geet

    ReplyDelete
  14. Ma'am we have our computer class x-a
    So can we leave

    ReplyDelete
  15. Maam I did answer on one of ur last commment

    ReplyDelete
  16. Brian , the answer is wrong... < > means NOT EQUAL TO. Even != also means NOT EQUAL TO. so, both are performing the same function. They can replace each other

    ReplyDelete
  17. The result of comparison operators also known as relational operators will be either TRUE or FALSE. The comparison maybe between numbers or strings but the result will be TRUE/FALSE

    ReplyDelete
  18. others?? if understood , send 👍 so that I plan my next class accordingly

    ReplyDelete

Post a Comment

Popular posts from this blog

HOLIDAY HW