Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

__gt__

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

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

PREVIOUS NEXT
Code Example
Python :: mean of torch tensor 
Python :: how to remove in null values in pandas 
Python :: request.body django 
Python :: tkinter starter code 
Python :: how to print hello world 
Python :: how to count range in django template 
Python :: sending email in django 
Python :: sns palette 
Python :: remove alphabetic characters python 
Python :: colab add library 
Python :: change case python 
Python :: learningrate scheduler tensorflow 
Python :: pytest parametrize 
Python :: merge two dataframes with common columns 
Python :: flask render_template 
Python :: exec to return a value python 
Python :: python get nearest value in list 
Python :: pandas map multiple columns 
Python :: min of numpy array 
Python :: python catch multiple exceptions 
Python :: flask get ip of user 
Python :: how to import model_to_dict 
Python :: change selected option optionmenu tkinter 
Python :: python procedured 
Python :: How to find xpath by contained text 
Python :: python average 
Python :: how to use ggplot matplotlib 
Python :: string to list separated by space python 
Python :: pyspark check all columns for null values 
Python :: python fill string with 0 left 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =