Search
 
SCRIPT & CODE EXAMPLE
 

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 __ne__ magic method 
Python :: Exception has occurred: FileNotFoundError 
Python :: python model feature importance 
Python :: NumPy rot90 Syntax 
Python :: hide ticks without hiding grid 
Python :: how to nest try/except statements 
Python :: make all subplots same height 
Python :: NumPy bitwise_or Code When inputs are arrays 
Python :: NumPy unpackbits Code Unpacked array along axis 1 
Python :: ROS subscribes to image type video frames (Python) through topic Publishing 
Python :: How to use "to_representation" hook for django rest serializers 
Python :: jenkins crumb python request 
Python :: lpython list unino 
Python :: Remove Brackets from List Using the * operator with the Separator method 
Python :: server localhost for shar file 
Python :: How to use a <ComboboxSelected virtual event with tkinter 
Python :: qmenu 
Python :: browser environment: 
Python :: long armstrong numbers 
Python :: install python 3 ubuntu 16.04 
Python :: How deploy Flask application on Webfaction 
Python :: find middle permutation of the string in python list 
Python :: pandas maxima and minima for given column 
Python :: difflib get close matches 
Python :: send whats app message using python 
Python :: matplotlib plot dpi - change format to svg 
Python :: dic to dic arrays must all be same length 
Python :: python durchschnitt liste 
Python :: how to bubble search in python stack overflow 
Python :: Three-dimensional Contour Plots 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =