Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python how to use __ge__

"""
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 :: __ne__ 
Python :: find max in for scartch python 
Python :: palindrome rearrange 
Python :: NumPy fliplr Example 
Python :: what are while loops in python 
Python :: use every character with python to get probabilities 
Python :: python fft 
Python :: NumPy bitwise_or Code When inputs are numbers 
Python :: NumPy unpackbits Code Unpacked array along axis 0 
Python :: django view - apiview decorator (urls.py config) 
Python :: center pyfiglet to terminal 
Python :: downsample audio 
Python :: python list and numpy array 
Python :: Remove Brackets from List Using String Slicing method 
Python :: login to sso.accounts.dowjones.com for wsj.com "python" 
Python :: SQL Query results in tkinter 
Python :: List change after copy Python 
Python :: Examples of correct code for this rule with global declaration: 
Python :: block-all-mixed-content csp bypass python 
Python :: string exercise 
Python :: Python beginner question - trying to understand return statement 
Python :: Evaluate mathematical expression 
Python :: python discord next page 
Python :: dictionary, accepting similar words solution 
Python :: pandas rolling list 
Python :: twitter api ("Connection broken: Invalid Chunk Length(got length b', 0 bytes read)" 
Python :: tkinter trig calculator 
Python :: output of an intermediate layer 
Python :: gun in python turtle 
Python :: matplotlib three dimensional plot 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =