Author: admin

  • Python Liskov Substitution Principle

    Summary: in this tutorial, you’ll learn about the Liskov Substitution Principle and how to implement it in Python. Introduction to the Liskov substitution principle The Liskov substitution principle (LSV) is one of the five principles in the SOLID principles. The L in SOLID stands for the Liskov substitution principle. The Liskov substitution principle states that…

  • Python Open–closed principle

    Summary: in this tutorial, you’ll learn about the open-closed principle to extend the system without directly modifying existing code. Introduction to the open-closed principle The open-closed principle is one of the five principles in the SOLID principle. The letter O in the SOLID stands for the open-closed principle. The open-closed principle states that a class, method, and function should…

  • Python Single Responsibility Principle

    Summary: in this tutorial, you’ll learn about the single responsibility principle and how to implement it in Python. What is SOLID SOLID is an abbreviation that stands for five software design principles compiled by Uncle Bob: The single responsibility is the first principle in the SOLID principles. Introduction to the single responsibility principle The single responsibility…

  • Python enum auto

    Summary: in this tutorial, you’ll learn about the enum auto() function to generate unique values for enumeration members. Introduction to the enum auto() function The following example defines an enumeration with three members whose values are 1, 2, and 3: In this example, we manually assign integer values to the members of the enumeration. To make it…

  • Customize and Extend Python Enum Class

    Summary: in this tutorial, you’ll learn how to customize and extend the custom Python enum classes. Customize Python enum classes Python enumerations are classes. It means that you can add methods to them, or implement the dunder methods to customize their behaviors. The following example defines the PaymentStatus enumeration class: The PaymentStatus enumeration has three members: PENDING, COMPLETED, and REFUND. The following displays the…

  • Python Enum aliases & @enum.unique Decorator

    Summary: in this tutorial, you’ll learn about enumeration member aliases and how to use the enum unique decorator to ensure the uniqueness of member values. Introduction to the enum aliases By definition, the enumeration member values are unique. However, you can create different member names with the same values. For example, the following defines the Color enumeration: In this…

  • Python Enumeration

    Summary: in this tutorial, you’ll learn about Python enumeration and how to use it effectively. Introduction to the Python Enumeration By definition, an enumeration is a set of members that have associated unique constant values. Enumeration is often called enum. Python provides you with the enum module that contains the Enum type for defining new enumerations. And you define…

  • Python Abstract Classes

    Summary: in this tutorial, you’ll learn about Python Abstract classes and how to use it to create a blueprint for other classes. Introduction to Python Abstract Classes In object-oriented programming, an abstract class is a class that cannot be instantiated. However, you can create classes that inherit from an abstract class. Typically, you use an abstract class…

  • Python __slots__

    Summary: in this tutorial, you will learn about the Python __slots__ and how how to use it to make your class more efficient. Introduction to the Python __slots__ The following defines a Point2D class that has two attributes including x and y coordinates: Each instance of the Point2D class has its own __dict__ attribute that stores the instance attributes. For example: By default, Python uses the dictionaries to manage the…

  • 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: The Employee class has three instance variables name, base_pay, and bonus. It also has the get_pay() method that returns the total of base_pay and bonus. Second, define the SalesEmployee class that inherits from the Employee class: The SalesEmployee class has four…