Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python __ge__ magic method

"""
Magic method __ge__ stands for greater than or equal. So this magic method defines or 
overwrites what should ">=" sign do with objects.
"""

class Test:
    def __init__(self, x):
        self.x = x
    
    def __ge__(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(2)
t2 = Test(2)
print(t >= t2)	# Now I call the __ge__ method by using ">=" sign.
Comment

PREVIOUS NEXT
Code Example
Python :: Python __le__ magic method 
Python :: split() without argument 
Python :: how to fetch limited rows in pandas dataframe using sqlalchemy 
Python :: NumPy unique Example Identify the index of the first occurrence of unique values 
Python :: python mxs Classof 
Python :: simpy 
Python :: beaglebone install python 3.7 
Python :: NumPy bitwise_or Syntax 
Python :: NumPy unpackbits Code Unpacked array along default axis 
Python :: django view - apiview decorator (retrieve, update or delete - GET, PUT, DELETE) 
Python :: qt list widget let editable 
Python :: discord python bot input 
Python :: how to show all rows whith a unique value in a column 
Python :: Remove Brackets from List Using the Translate method 
Python :: tuple python !g 
Python :: displaying print output in a textbox 
Python :: python extract multiple values from a single cell in a dataframe column using pandas 
Python :: Examples of incorrect code for this rule: 
Python :: pyqt serial plotter 
Python :: DOWNLOAD ANALYZE_DXP.PY 
Python :: Flask error: werkzeug.routing.BuildError 
Python :: DD python ue5 set material interface 
Python :: knn.score sklearn 
Python :: ring write the key and the IV directly using strings 
Python :: ring execute the program line by line 
Python :: mehrzeiliges kommentar python 
Python :: python sort array custom comparator 
Python :: substituir valor simbólico por valor real em uma equação Python 
Python :: how to hash out a big paragraph in vs code python 
Python :: print a commans in python 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =