Assignment operator:
Another type of operator we already know is assignment operator, we use them to assign values to variable
ASSIGNMENT OPERATORS
= Assigns a value to a variable
+= Adds a value to a variable
-= Subtracts a value from a variable
*= Multiplies a value with a variable
/= Divides the variable and assign a value
%= Assigns the remainder of a division
**= Assigns the result of a exponentiation
//= Assigns the result of a floor division to the variable
we use these operators to directly assign a value to the variable. the below two statement have same meaning . It’s just a simpler way to write
it.
a = a + 10
a += 10
Example
Comparison operator :
When we use comparison operator in order to compare two objects we always get a boolean. So our result is binary, either true or false
COMPARISON OPERATORS
== Equal Two values are the same
!= Not Equal Two values are not the same
> Greater Than One value is greater than the other
< Less Than One value is less than the other
>= Greater orEqual One value is greater than or equal to another
<= Less or Equal One value is less than or equal to another
We use comparison when we are dealing with condition and loops
When comparison is right it returns true else return false
Example:( run this in python shell)
10==10
20>10
20>20
20>=20
20<10
10<=5
Output:
In next post let see about the logical and membership operator!!
If you have doubts feel free to ask in comment section
Comments
Post a Comment