Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

__ne__

class Foo:
  def __init__(self, num):
    self.num = num
    
  def __eq__(self, other):
    return self.num == other.num
  
  def __ne__(self, other): # __ne__ represents the != operator
    return self.num != other.num
Comment

__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 :: split() without argument 
Python :: object at being output python 
Python :: pyqt log widget thread safe 
Python :: NumPy rot90 Example Rotating Three times 
Python :: using Canvas with tkinger 
Python :: how to run string like normal code in 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 bitwise_xor Code When inputs are arrays 
Python :: Convertion of an array into binary using NumPy binary_repr 
Python :: make a dict from td scrape 
Python :: numpy image processing 
Python :: taking str input in python and counting no of it 
Python :: penggunaan len di python 
Python :: Demonstration of Python range() 
Python :: text to speech free python 
Python :: How can I make portable python desktop application 
Python :: opencv2.3 
Python :: how to Capture only the ICMP packet. using bpf 
Python :: Fetch all links from a given webpage 
Python :: Flask application displaying list of items from SQL database as text 
Python :: cuenta atras segundero python 
Python :: Retry function for sending data 
Python :: get the first principle component of pca 
Python :: ring Using This in the class region as Self 
Python :: python run unix command 
Python :: Window freezes after clicking of button in python GTK3 
Python :: unpack list python 
Python :: matplotlib bring plot to front in plots with twin axis 
Python :: python min date from dictionary 
Python :: python image processing and resizing 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =