Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Python __le__

"""
Magic method __le__ stands for lesser 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 __le__(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 __le__ method by using "<=" sign.
Comment

PREVIOUS NEXT
Code Example
Python :: Python how to use __ne__ 
Python :: create different size matplotlib 
Python :: sorting a specific row python 
Python :: NumPy rot90 Example Rotating Once 
Python :: function nbYear(p0, percent, aug, p) { let n = 0; while(p0 < p) { p0 = p0 + Math.round(p0 * (percent/100)) + aug; n ++; } return n; } 
Python :: else clause in for loop python 
Python :: ignopre rankwarning pyton 
Python :: NumPy bitwise_or Code When inputs are Boolean 
Python :: NumPy binary_repr Syntax 
Python :: drop column 0 to many 
Python :: change admin password djano 
Python :: cast set 
Python :: penggunaan clear di python 
Python :: Creating a Dictionary using built-in function dict() 
Python :: run server localhost for shar file 
Python :: python tkinter.ttk combobox down event on mouseclick 
Python :: python random number between 1000 and 9999 
Python :: extract data using selenium and disable javascript 
Python :: empty list 
Python :: How to setup Conda environment and package access extension from within Jupyter 
Python :: pandas drop zeros from series 
Python :: python compare number with a precision 
Python :: discord.py main file setup 
Python :: ring define private attributes and methods 
Python :: python rational numbers 
Python :: matplotlib plot dpi - change format to retina instead of svg 
Python :: any value in list will retrun true python 
Python :: re.split return none in the list 
Python :: python if not explaned 
Python :: Wireframes and Surface Plots 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =