Python __sub__() Magic Method

Syntax object.__sub__(self, other) Python’s object.__sub__(self, other) method returns a new object that represents the difference of two objects. It implements the subtraction operator – in Python. We call this a “Dunder Method” for “Double Underscore Method” (also called “magic method”). To get a list of all dunder methods with explanation, check out our dunder cheat … Read more

Python __add__() Magic Method

Syntax object.__add__(self, other) Python’s object.__add__(self, other) method returns a new object that represents the sum of two objects. It implements the addition operator + in Python. We call this a “Dunder Method” for “Double Underscore Method” (also called “magic method”). To get a list of all dunder methods with explanation, check out our dunder cheat … Read more

Python __abs__()

Syntax object.__abs__() Python’s object.__abs__() method returns the absolute value of the object and implements the built-in function abs(). The absolute value of any numerical input argument -x or +x is the corresponding positive value +x. However, you can overwrite the default behavior by defining a custom __abs__() method. We call this a “Dunder Method” for … Read more

Python Dunder Methods Cheat Sheet

When searching for a list of dunder methods with explanations, i.e., a cheat sheet on Python magic methods, I only found a couple of resources all over the web—each covering only a fraction of dunder methods. So, here’s my collection of 127 dunder methods (also called “magic methods”) from those sources, sorted alphabetically. I provide … Read more

How to Install websocket-client in Python?

The Python websocket-client library is among the top 100 Python libraries, with more than 35,008,014 downloads. This article will show you everything you need to get this installed in your Python environment. Library Link How to Install websocket-client on Windows? Type “cmd” in the search bar and hit Enter to open the command line. Type … Read more