Blog

python tutorials and learn python

Created with Sketch.

Python super

Python super Summary: in this tutorial, you will learn how to use the Python super() to delegate to the parent class when overriding methods. Introduction to the Python super First, define an Employee class: class Employee: def __init__(self, name, base_pay, bonus): self.name = name self.base_pay = base_pay self.bonus = bonus def get_pay(self): return self.base_pay +…
Read more

Python Overriding Method

Python Overriding Method Summary: in this tutorial, you’ll learn how to use Python overriding method to allow a child class to provide a specific implementation of a method that is provided by one of its parent classes. Introduction to Python overriding method The overriding method allows a child class to provide a specific implementation of…
Read more

Python Inheritance

Python Inheritance Summary: in this tutorial, you’ll learn about Python inheritance and how to use the inheritance to reuse code from an existing class. Introduction to the Python inheritance Inheritance allows a class to reuse the logic of an existing class. Suppose you have the following Person class: class Person: def __init__(self, name): self.name =…
Read more

Python Delete Property

Python Delete Property Summary: in this tutorial, you’ll learn how to use the property() class to delete the property of an object. To create a property of a class, you use the @property decorator. Underhood, the @property decorator uses the property class that has three methods: setter, getter, and deleter. By using the deleter, you…
Read more

Python Readonly Property

Python Readonly Property Summary: in this tutorial, you’ll learn how to define Python readonly property and how to use it to define computed properties. Introduction to the Python readonly property To define a readonly property, you need to create a property with only the getter. However, it is not truly read-only because you can always…
Read more

Python Property Decorator

Python Property Decorator Summary: in this tutorial, you’ll learn about Python property decorator (@property) and more importantly how it works. Introduction to the Python property decorator In the previous tutorial, you learned how to use the property class to add a property to a class. Here’s the syntax of the property class: class property(fget=None, fset=None,…
Read more

Python Property

Python Property Summary: in this tutorial, you’ll learn about the Python property class and how to use it to define properties for a class. Introduction to class properties The following defines a Person class that has two attributes name and age, and create a new instance of the Person class: class Person: def __init__(self, name,…
Read more

Python __del__

Python __del__ Summary: in this tutorial, you will learn about the Python __del__ special method and understand how it works. Introduction to the Python __del__ method In Python, the garbage collector manages memory automatically. The garbage collector will destroy the objects that are not referenced. If an object implements the __del__ method, Python calls the…
Read more

Python __bool__

Python __bool__ Summary: in this tutorial, you will learn how to implement the Python __bool__ method to return boolean values for objects of a custom class. Introduction to the Python __bool__ method An object of a custom class is associated with a boolean value. By default, it evaluates to True. For example: class Person: def…
Read more

Python __hash__

Python __hash__ Summary: in this tutorial, you’ll learn about the Python hash() function and how to override the __hash__ method in a custom class. Introduction to the Python hash function Let’s start with a simple example. First, define the Person class with the name and age attributes: class Person: def __init__(self, name, age): self.name =…
Read more