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
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)
- Write detailed notes on:-
- arithmetic operators
- assignment operators
- comparison operators
- How is "=" different from "= =" operators?
- Differentiate between "/", "//" and the "%" operators.
- Differentiate between "< >" and " !=".
- What are shorthand operators? Give examples.
- What would be the result of
- an arithmatic expression
- a comparison
good morning maam
ReplyDeleteHi Clement.
DeleteThis comment has been removed by the author.
ReplyDeleteGood morning maam
ReplyDeleteBrian
Good morning mam
ReplyDelete-Aaron David
Not assignment but the Comparison/Relational Operators. Sorry
ReplyDeleteWe will begin the zoom session at 11 am. Kindly finish reading this concept before that
ReplyDeletePls understand the concept and note it down in the register. HW given at the end has to be done today. Submission tom
ReplyDeletepls switch to zoom class
ReplyDeleteGood mornig mam
ReplyDeleteAshish- present
There is some technical issue with zoom. Trying to connect back. Pls wait
ReplyDeleteLets come back to blog for discussion
ReplyDeleteGood morning ma'am
ReplyDelete-Geet
Ma'am zoom meeting
ReplyDeleteEnded
Yes it did
DeleteGeet you had a question. Pls share
ReplyDeleteMa'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.....
ReplyDelete-Geet
Beta some had missed the session and some others who didnt write. If u have, no need to repeat
DeleteOne Zoom class is of 40 minutes. Rest of the discussion on Blog pls
ReplyDeleteOk mam
DeleteOk ma'am
ReplyDeleteI am here ma'am
ReplyDeleteTejas
Is there any difference between < > and !=
ReplyDeleteYea I am here too
ReplyDeleteBrian
Is there any difference between < > and !=? Pls answer
ReplyDelete< the refers to if the right value is greater than the the left the condition is true
Delete> 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
Yes mam there is a difference
DeleteThere is a difference
DeleteMa'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.....
ReplyDelete-Geet
Ma'am we have our computer class x-a
ReplyDeleteSo can we leave
i think at 12, not now????
DeleteI am waiting for the answer...
ReplyDeleteMaam I did answer on one of ur last commment
ReplyDeleteBrian , 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
ReplyDeleteOk mam understood
DeleteGreat. God Bless you
DeleteThe 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
ReplyDeleteothers?? if understood , send 👍 so that I plan my next class accordingly
ReplyDeletegood morning ma'am
ReplyDelete-artham