Monday 13 June 2022

python @ decorators, how it differs with generators its best practices

Decorators and generators are both powerful features in Python, but they serve different purposes.

A decorator is a function that takes another function as input and returns a new function that usually modifies the behavior of the original function in some way. Decorators are commonly used for adding functionality to existing functions, such as caching, logging, or authentication.

Read more »

Labels: , ,

Sunday 8 May 2022

python private methods, how it differs with public methods best practices

In Python, private methods are methods that are intended to be used only within the class in which they are defined. Private methods are defined by prefixing the method name with two underscores (__) at the beginning of the method name.

Here is an example of a private method in Python:

class MyClass:

    def __init__(self, value):

        self.__value = value


    def __private_method(self):

        print("This is a private method.")


    def public_method(self):

        self.__private_method()


Read more »

Labels: , ,