Arithmetic operators

20 August 2020

Code

Add

# Add
x = 2 + 3  
y = np.add(2, 3)

print("x =", x)
print("y =", y)
x = 5
y = 5

.

Subtract

# Subtract
x = 2 - 3  
y = np.subtract(2, 3)

print("x =", x)
print("y =", y)
x = -1
y = -1

.

Multiply

# Multiply
x = 2 + 3  
y = np.multiply(2, 3)

print("x =", x)
print("y =", y)
x = 5
y = 6

.

Divide

# Divide
x = 2 / 3  
y = np.divide(2, 3)
z = np.true_divide(2, 3)

print("x =", x)
print("y =", y)
print("z =", z)
x = 0.6666666666666666
y = 0.6666666666666666
z = 0.6666666666666666

.

Floor divide

# Floor divide
x = 2 // 3  
y = np.floor_divide(2, 3)
print("x =", x)
print("y =", y)
x = 0
y = 0

.

Modulus

# Modulus
x = 2 % 3  
y = np.mod(2, 3)

print("x =", x)
print("y =", y)
x = -1
y = -1

.

Divmod

# Divmod
x = divmod(5, 2)
y = np.divmod(5, 2)

print("x =", x)
print("y =", y)
x = (2, 1)
y = (2, 1)

.

Absolute

# Absolute
x = abs(-1)
y = np.absolute(-1)

print("x =", x)
print("y =", y)
x = 1
y = 1

.






Any errors in code above?
Please send a message.