Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

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 :: python sorted lambda 
Python :: pyspark datetime add hours 
Python :: discord.py how to use permissions 
Python :: export_excel file python 
Python :: print a text in python 
Python :: unlimited keyword arguments python 
Python :: django making a custom 403 page 
Python :: static class python 
Python :: check if back is pressed python 
Python :: using while loop in python taking input until it matches the desired answer 
Python :: python make a list of odd numbers 
Python :: flask send client to another web page 
Python :: import matplotlib plt 
Python :: how to add 30 minutes in datetime column in pandas 
Python :: how to append data to csv file in python without replacing the already present text 
Python :: python mysqldb 
Python :: python run system command 
Python :: python update installed packages 
Python :: tkinter new line in text 
Python :: Flatten List in Python Using List Comprehension 
Python :: python apply function to dictionary values 
Python :: python find index of minimum in list 
Python :: select only some rows pandas 
Python :: code to find the shape of the 2d list in python 
Python :: Getting the Current Working Directory in Python 
Python :: add text to pygame window 
Python :: print ocaml 
Python :: how to restart program in python 
Python :: how to enable execution time in jupyter lab 
Python :: python pad with zeros 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =