Python‎ > ‎operator‎ > ‎

operator.eq()

http://www.adilwaseem.com/

Definition
The method test the equality of the values.

Syntax
operator.eq(a,b)
__eq__

Parameters
a=value
b=value

Import module
Importing module is required in the Shell window and the Editor window.

Examples
The method return with the result about the equality of list.
>>> a=["Python", "Lake"]
>>> b=["Python", "Lake"]
>>> c=["Python", "Research", "Centre"]
>>> operator.eq(a,b)
True
>>> operator.eq(b,c)
False
>>> operator.eq(c,a)
False

In this test, method tests the equality between tuple.
 >>> x=(1,2,3)
>>> y=(1,2,3)
>>> operator.eq(x,y)
True

a==b
The method also test the equality between the value.
 >>> 
>>> a=["Python", "Lake"]
>>> b=["Python", "Lake"]
>>> a==b
True
>>> a==c
False
>>> b==c
False
>>> 

operator.__eq__(a,b)
The method equal to operator.eq(a,b).
 >>> operator.__eq__(a,b)
True
>>> operator.__eq__(b,c)
False
>>> operator.__eq__(c,a)
False

__eq__
The set comparison results in False.
 >>> set1={4,5,6,7}
>>> set2={6,7,8,9,10}
>>> set1.__eq__(set2)
False

The method operator.inv() is equal to operator.invert() or not .
 >>> a=operator.invert(-22)
>>> b=operator.inv(-22)
>>> a.__eq__(b)
True
>>>

The equality is tested between pow(a,b) and operator.ipow(a,b):
 >>> import operator
>>> a=operator.ipow(3,4)
>>> b=pow(3,4)
>>> a.__eq__(b)
True

int(abs())
The output is True in __eq__ test.
 >>> int(abs(-81)).__eq__(9*9)
True
>>>

The return is:
from decimal import Decimal
import operator

a=Decimal(1).radix()
b=Decimal('10')
w=Decimal(a).radix().__eq__(b)
print("The value of a is equal to b: ", w)
>>>
The value of a is equal to b:  True
>>>


Comments