• Python Generators

    Python Generators

    Python Generators Table Of Contents: What Is Generator In Python? How To Create A Generator? Examples Of Generators. Advantages Of Using Generators. (1) What Is Generator In Python? The problem with iterators like list, set, tuple and dictionary is that they are too slow to fetch values from them. To solve this problem we have ‘Generators’ in Python. Generators help us to retrieve elements from the iterators like list, set, tuple and dictionary much faster ways, as compared to traditional using a ‘for’ loop to iterate. (2) How To Create A Generator In Python? The first step of creating a

    Read More

  • Python Decorators

    Python Decorators

    Python Decorators Table Of Contents: What Are Decorators In Python? Examples Of Decorators. Using Multiple Decorators. (1) What Are Decorators In Python? Decorators are just the usual methods used to add extra functionalities to an existing method. Python provides us with a way to add some extra functionality to an existing method, by using ‘Decorators’. Decorators actually don’t modify the codes inside the function, otherwise, it will cause serious security issues. Instead, it extends the function by adding some extra lines to it. Imagine a situation where you are using the methods from another file, that you don’t have access

    Read More

  • Python Closures

    Python Closures

    Python Closures Table Of Contents: What Is A Closure Method In Python? How To Use Closure Method In Python? Where To Use Closure Method In Python? Examples Of Closure Method. (1) What Is A Closure Method In Python? As the name suggests, the method which is inside another method is called the closure method. Because it is closed inside the parent method, hence the name closure method. What the extra Python is providing here is that you can return the closure method from the parent method. An important thing is that the closure method will be able to remember the

    Read More

  • Python Context Management

    Python Context Management

    Python Context Manager Table Of Contents: What Is Context Management? Benefits Of Context Management. Context Management Using ‘try’ with ‘finally’ Approach. Context Management Using ‘with’ statement. Context Management Using ‘__enter__()’ and ‘__exit__()’ method. (1) What Is Context Management? When you finished using something, you should keep that thing in its place, so that the next person can find it easily. Suppose after using your car key you through it somewhere in your house, next time when you want to drive it you won’t find it. So it is better to keep things in their place after using them. So in

    Read More

  • Python Magic Methods

    Python Magic Methods

    Add Your Heading Text Here Table Of Contents: What Is A Magic Function? Examples Of Magic Methods. Know The Magic Methods Inside The Class. (1) What Is A Magic Function? Magic methods in Python are the special methods that start and end with double underscores( __ ). They are also called dunder methods because they use double underscores(__). Magic methods are not designed to be invoked by the user, but the invocation happens internally from the class on a specific action. For example, when you initialize a class the __init__ method will be called automatically. Here __init__ method is called

    Read More

  • Python Lambda Function

    Python Lambda Function

    Python Lambda Function Table Of Content: What Is A Lambda Function? Lambda Function Syntax. Examples Of Lambda Function. Lambda Function With map( ) Function. Lambda Function With filter( ) Function. (1) What Is A Lambda Function ? Lambda functions are user-defined functions in Python, which have only a single statement to execute. The Lambda function can have any number of arguments but only one expression, which is evaluated and returned. As we know ‘def’ keyword is used to define a normal function, here, the ‘lambda’ keyword is used to define the Lambda function. Lambda functions are the nameless function, which

    Read More