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 __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 Requests Library – Exception Handling & Advanced request.get() Parameters

This is the first part of a 3-part series on the Python request library: Python Requests Library – Your First HTTP Request in Python Python Requests Library – Understanding requests.get() Parameters Python Requests Library – Exception Handling & Advanced request.get() Parameters Syntax Background & Preparation The Requests library has several methods for GET. Part 1 … Read more

Python Requests Library – Your First HTTP Request in Python

This is the first part of a 3-part series on the Python request library: Python Requests Library – Your First HTTP Request in Python Python Requests Library – Understanding requests.get() Parameters Python Requests Library – Exception Handling & Advanced request.get() Parameters Syntax Background There are many libraries around that make HTTP requests. However, the requests … Read more

How to Use FTX REST API in Python

This article explains how to use the REST API to access FTX in Python so that you can build your trading program. As you go through the article, you can also watch our article tutorial video: What is FTX? FTX is an exchange where users can trade various digital assets, such as cryptocurrencies, tokenised stocks … Read more

Python Depth-First Search (DFS) Algorithm

What is a Depth-First Search (DFS) Algorithm? Building on our previous story about graphs and graph traversal algorithms, this time we will look into a depth-first search algorithm. A depth-search algorithm also traverses a graph by exploring it vertex-by-vertex, but it does it by following the vertical order of the vertices. Although the depth-first search … Read more

Python Dictionary Methods

Method Name Method Description dict.clear() Removes all elements from the dictionary dict.copy() Creates a shallow copy of the dictionary dict.fromkeys() Create a new dictionary from a given iterable of keys dict.get() Returns value associated with a key, or default value if key does not exist dict.items() Outputs a list of (key, value) tuple pairs of … Read more

Python dict.keys() Method

πŸ’‘ Summary: To get a list of all the keys stored in a dictionary, use the dict.keys() method that returns a dict_keys object that is iterable but not ordered and not subscriptable. In this article, I will show some examples of the dict.keys() method to, hopefully, give you a better idea of how the method … Read more

Python dict.get() Method

Summary: When working with Python dictionaries, in some cases you may want to access a specific value of a certain item, this is where the dict.get() method comes in handy. Definition: Python’s dict.get() method expects a key argument. If the specified key is in the dictionary, the method will output the value associated with the … Read more