Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python __ne__ magic method

"""
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 :: find max in for scartch python 
Python :: modles en django 
Python :: how to get defintiion of pysspark teable 
Python :: NumPy rot90 Example Rotating four times 
Python :: setstylesheet python 
Python :: funcs_and_args for loop python 
Python :: how to increment date in python 
Python :: NumPy bitwise_xor Code When inputs are Boolean 
Python :: django disable foreign key checks temporary 
Python :: miniforge cv2 vscode 
Python :: qlcdnumber set value 
Python :: Python matplotlib multiple bars 
Python :: penggunaan items di python 
Python :: call a Python range() using range(stop) 
Python :: how to stop python file using batch file 
Python :: BeautifulSoup : Fetched all the links on a webpage how to navigate through them without selenium 
Python :: python regex exclude letters 
Python :: how to make a half pyramid in python 
Python :: Library for removal of punctuation and defining function 
Python :: Flask_SQLAlchemy is claiming my value is not boolean 
Python :: Determining the Data Type 
Python :: python 3.9.13 release date 
Python :: import all csv as individual dataframes python 
Python :: tkinter disabled but selectable 
Python :: python data statics 
Python :: search for file in a whole system 
Python :: how to download feature engine in spyder console 
Python :: insertar en una lista anidada python 
Python :: FinnT730 
Python :: image processing and resizing with python 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =