Monday, 19 August 2019

1.15 Operators and expressions


Operators and expressions:
Arithmetic Operators:
Addition +, Add two operands
 Substraction -, Subtract two operands
 Multiplication *, multiply two operands
Division /, divide two operands
floor division //, Divide and round off
Modulo division % , divide and give reminder as output
Program:
x=11
y=5
addition = x+y
substraction = x-y
multiplication=x*y
division= x/y
floordivision=x//y
modulodiv=x%y
print('x=',x,'y=',y)
print('addition=',addition)
print('substraction=',substraction)
print('multiplication',multiplication)
print('division',division)
print('floordivision',floordivision)
print('modulodiv',modulodiv)
Output:
x= 11 y= 5                                                                                                                       
addition= 16                                                                                                                     
substraction= 6                                                                                                                  
multiplication 55                                                                                                                
division 2.2                                                                                                                     
floordivision 2                                                                                                                  
modulodiv 1      

Logical Operators:
Logical AND, true if both operands are true else false.  x and y
Logical OR, true if any one of the operands is true else false.  x or y
Logical NOT, true if operand is false. not x
Relational Operators:
Greater Than >
Less Than <
Equal to ==
Not Equal to !=
Greater than equal >=
Less than equal <=

Expressions in Python
Expressions are representations of value. They are different from statement in the fact that statements do something while expressions are representation of value. For example, any string is also an expression since it represents the value of the string as well.

No comments:

Post a Comment