user52676
0
Q:

arithmetic operators in python

Arithmetic operators: Arithmetic operators are used to perform mathematical 
  operations like addition, subtraction, multiplication and division.
1
# Python Operators
Operator	Name			Example
+			Addition		x + y	
-			Subtraction		x - y	
*			Multiplication	x * y	
/			Division		x / y	
%			Modulus			x % y	
**			Exponentiation	x ** y	
//			Floor division	x // y
17
% : Modulus - remainder of the division of left operand by the right
  	x % y (remainder of x/y)
2
# operations in numbers with python 
a = 15
b = 3
#a and b are not expression because they are at the right side

print(a + b)    # this will add the numbers
print(a - b)    # this will subtract the numbers
print(a * b)    # this will multiply the numbers
print(a / b)    #this will divide the numbers
print(a // b)   #this will gives the reminder after division
2
# Below follow the math operators that can be used in python
# ** Exponent	
2 ** 3 # Output: 8
# % Modulus/Remaider	
22 % 8 # Output: 6
# // Integer division	
22 // 8 # Output: 2
# / Division	
22 / 8 # Output: 2.75
# * Multiplication	
3 * 3 # Output: 9
# - Subtraction	
5 - 2 # Output: 3
# + Addition	
2 + 2 # Output: 4
1
# Below follow the comparison operators that can be used in python
# == Equal to
42 == 42 # Output: True
# != Not equal to
'dog' != 'cat' # Output: True
# < Less than
45 < 42 # Output: False
# > Greater Than
45 > 42 # Output: True
# <= Less than or Equal to
40 <= 40 # Output: True
# >= Greater than or Equal to
39 >= 40 # Output: False
0

New to Communities?

Join the community