• 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

  • Python Reduce Function

    Python Reduce Function

    Python Reduce Function Table Of Contents: What Is Python Reducer? How To Implement Python Reducer? Examples Of Python Reducer? (1) What Is Python Reducer? If you want to apply some aggregate functions to an iterable like, adding, subtracting, multiplying, or concatenating all the values, then you can use the Python reduce() function. Python has an inbuilt reduce() function which you can import from “functools” module. (2) How To Implement Python Reducer? Syntax: import functools functools.reduce(function, iterable) Arguments: function – This function will be applied to all the elements in an iterable in a cumulative manner to compute the result. iterable

    Read More

  • Python Filter Function

    Python Filter Function

    Python Filter Function Table Of Contents: What Is A Filter Function? Syntax Of Filter Function. Examples Of Filter Function. (1) What Is A Filter Function? Python filter( ) method is an inbuilt method, which is used to filter out the required values from an iterable like(a list, tuple, set, or dictionary). The filter( ) method will return an iterator that you can easily convert iterators to sequences like lists, tuples, strings etc. (2) Syntax Of Filter Function. filter(function, iterable) Filter Parameters: function: A Function to be run for each item in the iterable iterable: The iterable to be filtered. Filter

    Read More

  • Python Map Functions

    Python Map Functions

    Python Map Functions Table Of Contents: What Is Map Function? Syntax Of Map Function. Examples Of Map Function. (1) What Is A Map Function? The map( ) function is an in-built python function, which is used to apply a given function to each item of an iterable (list, tuple etc.) The map( ) function will return an iterator (list, tuple etc) as an output. (2) Syntax Of Map Function? map(function, iterable) The map( ) Parameters: The map( ) function takes two parameters:(1) function – a function that performs some action on each element of an iterable(2) iterable – an iterable

    Read More

  • Python Extended Keyword Arguments(*args, **kwargs

    Python Extended Keyword Arguments(*args, **kwargs

    Python Extended Keyword Arguments(*args, **kwargs) Table Of Contents: What Are Extended Keyword Arguments? What Is Python *args? What Is Python **kwargs? Using Both *args and **kwargs. (1) What Is Extended Keyword Arguments? Arguments are the values passed to the function, for further processing. Most of the time you will know how many arguments a function can take. But, sometimes the argument counts can vary, and then your function will fail to accommodate those arguments. To handle this issue we have ‘Extended Keyword Arguments‘. Without Extended Keyword Arguments. def student(name,rollno,subject): print(‘Student Name:’,name) print(‘Student RollNo:’,rollno) print(‘Student Subject:’,subject) student(‘Abhispa’,’143′,’Math’,99) Output: TypeError Traceback (most

    Read More