Category: Tutorials
-
Reflection
In object-oriented programming, reflection refers to the ability to extract information about any object in use. You can get to know the type of object, whether is it a subclass of any other class, what are its attributes, and much more. Python’s standard library has several functions that reflect on different properties of an object. Reflection is also sometimes called introspect.…
-
Enums
Enums in Python In Python, the term enumeration refers to the process of assigning fixed constant values to a set of strings so that each string can be identified by the value bound to it. The Enum class included in enum module (which is a part of Python’s standard library) is used as the parent class to define enumeration…
-
Wrapper Classes
A function in Python is a first-order object. A function can have another function as its argument and wrap another function definition inside it. This helps in modifying a function without actually changing it. Such functions are called decorators. This feature is also available for wrapping a class. This technique is used to manage the class after it is…
-
Singleton Class
In Python, a Singleton class is the implementation of singleton design pattern which means this type of class can have only one object. This helps in optimizing memory usage when you perform some heavy operation, like creating a database connection. If we try to create multiple objects for a singleton class, the object will be created only…
-
Anonymous Class and Objects
Python’s built-in type() function returns the class that an object belongs to. In Python, a class, both a built-in class or a user-defined class are objects of type class. Example Open Compiler It will produce the following output − The type() has a three argument version as follows − Syntax Using above syntax, a class can be dynamically created. Three…
-
Inner Classes
Inner Class in Python A class defined inside another class is known as an inner class in Python. Sometimes inner class is also called nested class. If the inner class is instantiated, the object of inner class can also be used by the parent class. Object of inner class becomes one of the attributes of the outer…
-
Packages
In Python, the module is a Python script with a .py extension and contains objects such as classes, functions, etc. Packages in Python extend the concept of the modular approach further. The package is a folder containing one or more module files; additionally, a special file “__init__.py” file may be empty but may contain the package list. Create a Python Package Let us…
-
Interfaces
In software engineering, an interface is a software architectural pattern. It is similar to a class but its methods just have prototype signature definition without any executable code or implementation body. The required functionality must be implemented by the methods of any class that inherits the interface. The method defined without any executable code is known as…
-
Encapsulation
Encapsulation is the process of bundling attributes and methods within a single unit. It is one of the main pillars on which the object-oriented programming paradigm is based. We know that a class is a user-defined prototype for an object. It defines a set of data members and methods, capable of processing the data. According to the principle of…
-
Abstraction
Abstraction is one of the important principles of object-oriented programming. It refers to a programming approach by which only the relevant data about an object is exposed, hiding all the other details. This approach helps in reducing the complexity and increasing the efficiency of application development. Types of Python Abstraction There are two types of abstraction. One…