__eq__


Definition
The operator test the equality of the values.

Syntax
__eq__

Examples
The tested the equality of the equation.
 >>> complex(2.1+0j).__eq__(2.1)
True
>>>

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


Fraction().__eq__Fraction()
The method tested the equality:
 >>> Fraction(1).from_decimal(0).__eq__(Fraction(0,1))
True


The returned True:
 >>> Fraction(0,1).real.__eq__(Fraction(0, 1))
True


The return is equal to:
 >>> Fraction(1).from_float(1).__eq__(Fraction(1, 1))
True
 
The return is:
 >>> Fraction(2.1).__eq__(Fraction(2.1).imag)
False

Fraction()___eq___Fraction()
The return is following:
>> Fraction(2.11130032211111933).limit_denominator(100).__eq__(Fraction(2.1113003933).
limit_denominator(1000))
False

Fraction()__eq__()
The equality tested here:
 >>> Fraction(2,3).numerator.__eq__(2)
True


The return is:
 >>> Fraction(2.111300).limit_denominator(1).__eq__(Fraction(2, 1))
True

The equal to:
 >>> x="Adil Waseem"
>>> y="AdilWaseem"
>>> x.__eq__(y)
>>> x==y
False

str.__eq__(str)
The equal to:
 >>> x="Adil Waseem"
>>> y="AdilWaseem"
>>> x.__eq__(y)
>>> x==y
False

str.swaps.__eq__(str)
The returns are following:
>>> x="Python Lake"
>>> x.swapcase()
'pYTHON lAKE'
>>> str.swapcase("Python Lake")
'pYTHON lAKE'
>>> str.swapcase(x)
'pYTHON lAKE'
>>> x.swapcase().__eq__('pYTHON lAKE')
True
>>> x.swapcase()=='pYTHON lAKE'
True
>>>


str.rstrip().__eq__(str)
The returns are:
 >>> "Python Lake ".rstrip()
'Python Lake'
>>> "Python Lake                            ".rstrip().__gt__("Python Lake ".rstrip())
False
>>> "Python Lake                            ".rstrip().__eq__("Python Lake ".rstrip())
True
>>> "Python Lake                             ".rstrip().__eq__("Python Lake")
True
>>> "Python Lake                             ".rstrip().__eq__(str("Python Lake"))
True
>>> type("Python Lake ".rstrip())
<class 'str'>
>>>

The returns are :
 >>> type("Python".rjust(10))
<class 'str'>
>>> "Python".rjust(10).__eq__('    Python')
True
>>> len('    Python')
10
>>> len("Python".rjust(10))
10
>>> 


str.split().__eq__[list]
The return as following:
 >>> x=str.split("Python Lake")
>>> x
['Python', 'Lake']
>>> y=["Python", "Lake"]
>>> x==y
True
>>> x.__eq__(y)
True
>>> str.split("Python Lake").__ne__(["Python", "Lake"])
False
>>> 

str.isupper.__eq__(str.upper())
The return are following:
 >>> x="PYTHON LAKE".isupper()
>>> y="python lake".upper()
>>> x==y
False
>>> "PYTHON LAKE".isupper()==("python lake".upper())
False
>>> "PYTHON LAKE".isupper()
True
>>> "python lake".upper().__eq__("PYTHON LAKE")
True
>>> True.__eq__(True)
True
>>>


str.startswith().__eq__(str)
The return is equal to:
 >>> "Python Lake".startswith("P")
True
>>> "Python Lake".startswith("y")
False
>>> x="Python Lake"
>>> x.startswith("Lake")
False
>>> str.startswith("Python Lake", "p").__eq__(False)
True
>>> x=str.startswith("Python Lake", "p")
>>> y=True

str.isspace().__eq__()
The following are outcome:
 >>> str.isspace("").__eq__(False)
True
>>> x=""
>>> x.isspace().__ne__(True)
True


str.istitle().__eq__()
The return are equal to:
 >>> 
>>> "Python Lake".istitle().__eq__(True)
True
>>> "Python Lake".istitle().__ne__(False)
True
>>> "Python lake".istitle().__eq__(True)
False
>>> "python lake".istitle().__eq__(True)
False
>>> "PYTHON LAKE".istitle().__eq__(True)
False
>>>


str.__eq__str.splitlines()
Equal test on conducted on the string and other str.splitlines.
 >>> x="Python Reserch Centre"
>>> x.splitlines()
['Python Reserch Centre']
>>> type(x.splitlines())
<class 'list'>
>>> y=x.splitlines()
>>> x==y
False
>>> x.splitlines().__eq__(['Python Reserch Centre'])
True
>>> x.splitlines()==(['Python Reserch Centre'])
True
>>> test1=x.splitlines()
>>> test2=['Python Reserch Centre']
>>> test1==test2
True
>>> 

str.isdigit().__eq__(True)
The returned as:
 >>> 
>>> "Python Lake".isdigit()
False
>>> x="Python Lake"
>>> x.isdigit()
False
>>> str.isdigit(x)
False
>>> str.isdigit(x).__eq__(False)
True
>>> str.isdigit(x).__ne__(False)
False

str.maketrans.__eq__(dict)
Returns are:
 >>> x="1234"
>>> y="5678"
>>> z=str.maketrans(x,y)
>>> z
{49: 53, 50: 54, 51: 55, 52: 56}
>>> 
>>> z.__eq__({49: 53, 50: 54, 51: 55, 52: 56})
True
>>> z.items()
dict_items([(49, 53), (50, 54), (51, 55), (52, 56)])
>>> z.values()
dict_values([53, 54, 55, 56])


The return are as:
 >>> "Python Lake".isnumeric()
False
>>> str.isnumeric("Python Lake")
False
>>> x="Python Lake"
>>> x.isnumeric()
False
>>> x.isnumeric().__eq__(True)
False
>>> y=x.isnumeric()
>>> x is y
False


The return are as:
 >>> "Python Lake".isnumeric()
False
>>> str.isnumeric("Python Lake")
False
>>> x="Python Lake"
>>> x.isnumeric()
False
>>> x.isnumeric().__eq__(True)
False
>>> y=x.isnumeric()
>>> x is y
False


class.....: def __init__()......:....string==str.isidentifier(),str.lower(), str.isapha()
The function tested whether the string value is single word, or contain non-string values through input().
 class str_methods():
    def __init__(self, a,b,c):

        identifier=str.isidentifier(a)

        if str.isidentifier(a).__eq__(True):
            print("Full name should not contain special characters or numbers")
            
        else:
            print("Your full not name accepted")

        
      
        alpha=str.isalpha(b)
        
        if alpha.__ne__(False):
            print("Full name accepted")

            lower=str.lower(c)
            if lower.__eq__(str.lower(c)):
                 str.upper(c)
                 print("System convert your name to uppercase:", str.upper(c))
            else:
                 print("Your name accepted")

        else:
            print("Full name can't be one word")

                    

input_text=input("Please enter  your full name: ")

str_methods(input_text, input_text,input_text)
    
          

>>> 
Please enter your full name: Adil22
Full name should not contain special characters or numbers
Full name can't be one word
>>>        


class....: def....: if ....: __eq__
The class method return the complex values and tested the equality of the values.
 class complex_value:
    def __init__(self, a,b,c):

        self.a=complex(a).conjugate()
        self.b=complex(b).imag
        self.c=complex(c).real

        print("The comlex conjugate value of a is: ",self.a)
        print("The complex imag value of b is: ",self.b)
        print("The complex  real value of c is: ",self.c)
        
        if self.a.__eq__(complex(a).conjugate()):
            print("The value of a is equal to complex(a) conjugate")
        else:
             print("The value of a is NOT equal to complex(a) conjugate")
            

        if self.b.__eq__(complex(b).imag):
            print("The value of b is equal to complex(b) imag")
        else:
            print("The value of b is NOT equal to complex(b) imag")


        if self.c.__eq__(complex(c).real):
            print("The value of c is equal to complex(c) imag")
        else:
            print("The value of c is NOT equal to complex(c) imag")

           
value1=81
value2=222
value3=33
complex_value(value1,value2, value3)

>>> 
The comlex conjugate value of a is: (81-0j)
The complex imag value of b is: 0.0
The complex real value of c is: 33.0
The value of a is equal to complex(a) conjugate
The value of b is equal to complex(b) imag
The value of c is equal to complex(c) imag
>>>


Here is how Error method printed the error message.
 import webbrowser

x=input("Please enter web dress:")

if x.__eq__('www.pythonlake.com'):
    webbrowser.open(x)

    webbrowser.Error("Not allowed to access the file")

>>> 
Please enter web dress:www.amazon.com
Not allowed to access the file
>>> 

Comments