Blog Posts
-
Why are the statements in a class body executed before any instances of the class are created?
dr. Dobreff Csaba 5th máj 2026Objects bundle together logically related data (which describe the state of the object) and callable objects that operate on that data, namely methods. This is known as “encapsulation”. For objects...
-
Can multiple closure functions access the same enclosed local variable?
dr. Dobreff Csaba 24th ápr 2026The short answer is yes. The real question is how. The reason why this topic is interesting is that when we talk about closures, we usually think of a single...
-
What Are Shallow and Deep Copies?
dr. Dobreff Csaba 13th ápr 2026Sometimes we need to create copies of objects. At first glance, this might not seem particularly exciting. However, when it comes to compound objects, a few important questions arise. We...
-
What is a function decorator and when to use it?
dr. Dobreff Csaba 1st ápr 2026In the previous post, we mentioned that one of the many use cases of closures is the creation of decorators. You get a function decorator by passing a function object...
-
What is a closure and what is it used for?
dr. Dobreff Csaba 23rd márc 2026In Python, closures appear in many different use cases. For example, decorators, which are one of the characteristic language constructs in Python, are built on them. A function that is...
-
Why Lists Should Be Homogeneous but Tuples Can Be Heterogeneous?
dr. Dobreff Csaba 14th márc 2026In Python, a list can hold objects of any type. A list is a mutable container, which means that its elements can be replaced during program execution, and the number...
-
setdefault() vs defaultdict — Which Should You Use?
dr. Dobreff Csaba 11th márc 2026Both of these Python features are designed to handle the same situation: when a key is missing from a dictionary, they automatically create it with a specified default value. If...
-
How Can You Check If an Object Is Iterable?
dr. Dobreff Csaba 10th jan 2026You’ve probably already heard of iterable objects and iterators — and you’ve likely used them, too. These include any objects you can loop through using a for-loop, retrieving one element...
-
Did you know that you can create instances of a class using different sets of arguments?
dr. Dobreff Csaba 10th jan 2026Let’s consider a class that makes it possible to create triangle instances based on the lengths of their three sides. In this case, the __init__ method accepts three parameters, one...
-
How to Increase Code Flexibility with Function and Method Overloading
dr. Dobreff Csaba 10th jan 2026In this post, code flexibility refers to how much existing code needs to be changed when new requirements arise. A flexible piece of code is one where new needs can...