Python‎ > ‎operator‎ > ‎

operator.sub()


Definition
The return with the subtraction of a and b.

Syntax
operator.sub(a,b)

Parameters
Numbers

Examples
The method returns the value.
 >>> complex(2255888+0j).__sub__(22.9)
(2255865.1+0j)


The returns is:
 >>> a= Decimal(2.31).compare_total_mag(Decimal(9.22))
>>> b=Decimal('-1')
>>> operator.sub(a,b)
Decimal('0')

math.sin().__sub__
The input() value returns the math.sin(a)*2-1
import math
import operator
a=float(input("Please enter sine(value) : "))
b=math.sin(a).__mul__(2).__sub__(1)
print(b)
>>> 
Please enter sine(value) : 2.2
0.6169928076391802
>>>


Decimal().__sub__Decimal()
The method test the equality tow Decimal equations.
from decimal import Decimal

x=(Decimal(1).logical_and(Decimal(1))).__sub__(Decimal(0).logical_and(Decimal(1)))
y=(Decimal(1).logical_and(Decimal(1))).__mul__(Decimal(0).logical_and(Decimal(1)))
print(x.__eq__(y))

>>> 
False
>>>


int(round(operator.sub(a,b)))
The method returns with the for loop after finding the subtraction of random values.
import operator
import random
a=random.triangular(7,14)
b=random.uniform(2,5)
x=int(round(operator.sub(a,b)))
for i in range(x, 30):
    print(i)
    if i.__ge__(30):
        b=int(round(random.paretovariate(3)))
        print(i)

>>> 
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
>>>

Comments