Python __bool__() Magic Method

Syntax object.__bool__(self) The Python __bool__() method implements the built-in bool() function. So, when you cal bool(x), Python attempts to call x.__bool__(). If the return value is not a Boolean, Python raises a TypeError. We call this a “Dunder Method” for “Double Underscore Method” (also called “magic method”). To get a list of all dunder methods … Read more

Python __await__() Magic Method

The __await__() magic method defines the behavior of an awaitable object. An awaitable object is used to implement asynchronous behavior in Python. For example, you can implement an asynchronous function that waits for the data based to access some data like so (see source): Syntax __await__() object.__await__(self) The __await__() method must return an iterator. Otherwise, … Read more

Python __annotations__ Attribute

Annotations are defined in PEP 3107 allow you to add arbitrary metadata to the parameters and return values of functions. The __annotations__ attribute of a function object stores those annotations in a dictionary mapping function parameters or the return value to the specified annotations. Let’s have a look at a couple of examples next. Parameter … Read more

How to Earn $4000/M Passive Income as a Coder?

Everybody talks about passive income these days. Is it a scam? Yes and no. Nothing can exist passively for an unlimited time. Here’s what passive income really means: passive income is a more or less slowly dying income stream. But the idea is still powerful and transformative. And there are a lot of income streams … Read more

Python __ixor__() Magic Method

Syntax object.__ixor__(self, other) The Python __ixor__() magic method implements the in-place bitwise XOR x ^= y that calculates the result of the bitwise XOR operation x ^ y, and assigns it to the first operands’ variable x. This type of in-place operation is also called augmented arithmetic assignment. The method simply returns the new value … Read more

Python __ior__() Magic Method

Syntax object.__ior__(self, other) The Python __ior__() magic method implements the in-place bitwise OR x |= y that calculates the result of the bitwise OR operation x | y, and assigns it to the first operands’ variable x. This type of in-place operation is also called augmented arithmetic assignment. The method simply returns the new value … Read more

Python __iand__() Magic Method

Syntax object.__iand__(self, other) The Python __iand__() magic method implements the in-place bitwise AND x &= y that calculates the result of the bitwise AND operation x & y, and assigns it to the first operands’ variable x. This type of in-place operation is also called augmented arithmetic assignment. The method simply returns the new value … Read more

Python __ipow__() Magic Method

Syntax object.__ipow__(self, other) The Python __ipow__() magic method implements the in-place exponentiation x **= y that calculates the result of the power function x ** y, and assignsit to the first operands’ variable x. This type of in-place operation is also called augmented arithmetic assignment. The method simply returns the new value to be assigned … Read more

Python __imod__() Magic Method

Syntax object.__imod__(self, other) The Python __imod__() magic method implements the in-place modulo operation x %= y that calculates the modulo operation x % y, and assigns the result to the first operands variable x. This type of in-place operation is also called augmented arithmetic assignment. The method simply returns the new value to be assigned … Read more

Python __ifloordiv__() Magic Method

Syntax object.__ifloordiv__(self, other) The Python __ifloordiv__() magic method implements the in-place floor division operation x //= y that calculates the integer division operation x // y, and assigns the result to the first operands variable x. This operation is also called augmented arithmetic assignment. The method simply returns the new value to be assigned to … Read more

Python __itruediv__() Magic Method

Syntax object.__itruediv__(self, other) The Python __itruediv__() magic method implements the in-place division operation x /= y that calculates the division operation x / y, and assigns the result to the first operands variable x. This operation is also called augmented arithmetic assignment. The method simply returns the new value to be assigned to the first … Read more