Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python __ne__

"""
Magic method __ne__ stands for not equal. So this magic method defines or 
overwrites what should "!=" sign do with objects.
"""

class Test:
    def __init__(self, x):
        self.x = x
        
    def __ne__(self, other):
        """
		Compares attribute "x" of objects, self stands for 1st object
		and other stands for object after "!=" sign. (so t is self and t2 other)
		"""
        return self.x != other.x	# Should be used on objects of the same type
    


t = Test(3)
t2 = Test(2)
print(t != t2)	# Now I call the __ne__ method by using "!=" sign.
Comment

PREVIOUS NEXT
Code Example
Python :: Python __sub__ magic method 
Python :: Python __truediv__ magic method 
Python :: Python __le__ magic method 
Python :: django ejemplo de un formulario crud 
Python :: NumPy trim_zeros Syntax 
Python :: what are while loops in python 
Python :: else clause in for loop python 
Python :: Program to illustrate the use of nested if statement Average in python Grade =80 and above A =70 and <80 B =60 and <70 C =50 and <60 D Otherwise 
Python :: NumPy invert Code When the input is a number 
Python :: WAP to input 3 no.s and print their sum. 
Python :: Printing a long code line to span over multiple lines 
Python :: # convert dictionary keys to a list 
Python :: ExpressionalRebel 
Python :: tkintre sub windows 
Python :: python code to java code converter 
Python :: ccacxc 
Python :: gremlin python import 
Python :: how to create function python 
Python :: seaborn colorbar labelsize 
Python :: python event emitter 
Python :: app.callback output is not defined 
Python :: get command line variables python 
Python :: containsDuplicate Set Solution 
Python :: ring Date and Time Clock 
Python :: nnumpy matrix count non negative values 
Python :: python get message Exception 
Python :: matplotlib doesnt show suptitle 
Python :: downloading datasets from ml.org repository 
Python :: create new column pandas and order sequence 
Python :: pylatex multicolumn align 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =