Category: New Python tutorial

python tutorials and learn python

Created with Sketch.

Python enum auto

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: from enum import Enum class State(Enum): PENDING = 1 FULFILLED = 2…
Read more

Customize and Extend Python Enum Class

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…
Read more

Python Enum aliases & @enum.unique Decorator

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…
Read more

Python Enumeration

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…
Read more

Python Abstract Classes

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.…
Read more

Python __slots__

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: class Point2D: def __init__(self, x, y): self.x = x self.y…
Read more

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