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 :: Exception has occurred: FileNotFoundError 
Python :: how to fetch limited rows in pandas dataframe using sqlalchemy 
Python :: NumPy resize Example out of bound values [appending zeros] 
Python :: NumPy bitwise_and Example When inputs are numbers 
Python :: pandas listagg equivalent in python 
Python :: 16. count total numbers of uppercase and lowercase characters in input string python 
Python :: python string josin 
Python :: NumPy invert Code When the input is a number 
Python :: URL to origin python 
Python :: django check for empty onetoone exists 
Python :: selenium python select elements data atribute 
Python :: how to take input as an integer in python 
Python :: penggunaan keys di python 
Python :: call a Python range() using range(start, stop) 
Python :: python dependency injection 
Python :: Python script to download all images from a website to a specified folder with BeautifulSoup 
Python :: send by email in odoo 14 
Python :: ternary operator in list comprehension python 
Python :: problème barbier semaphore python 
Python :: first duplicate 
Python :: Converting Data Types 
Python :: django add list to manytomany 
Python :: how to scrape data from github api python 
Python :: print all gpu available tensor 
Python :: Hiding and encrypting passwords in Python? 
Python :: pairplot seaborn legend best position set 
Python :: convert python code to c++ online 
Python :: pandas count zeros in column 
Python :: ffmpeg python get total frames 
Python :: oaxaca 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =