• Python – What Is Singleton Class ?

    Python – What Is Singleton Class ? Table Of Content: What Is Singleton Class ? Example Of Singleton Class. Where Do We Use Singleton Class? Why Do We Want To Use Singleton Class? Advantages Of Singleton Class. When Not To Use Singleton Class? One Liner Summary. (1) What Is Singleton Class ? (2) Example Of Singleton Class . (3) Where Do We Use Singleton Class ? (4) Why Do We Want To Use A Singleton? (5) Advantages Of Singleton Class. (6) When Not To Use Singleton Class ? (7) One-liner summary (8) Let’s Compare BEFORE vs AFTER Singleton For Each

    Read More

  • Python – What Is Enum Classes ?

    Python – What Is Enum Class ? Table Of Content: What Is Enum ? Why Do We Use Enum ? Example Of Enum Class ? What Does StrEnum Means ? Where Do Enums Shine ? Benefits Of Enum ? Summary. (1) What Is Enum ? (2) Why Do We Use Enum ? (4) Example Of Enum. (5) What Is StrEnum ? Example-1: Without StrEnum from enum import Enum class LLMType(Enum): CHAT = "chat" EMBEDDING = "embedding" SPEECH2TEXT = "speech2text" task_type = LLMType.SPEECH2TEXT print(task_type) LLMType.SPEECH2TEXT Example-2: With StrEnum from enum import StrEnum class LLMType(StrEnum): CHAT = "chat" EMBEDDING = "embedding" SPEECH2TEXT

    Read More

  • Python – What Is Pydantic Library ?

    Python – What Is Pydantic Library ?

    Python – What Is Pydentic Python Library ? Table Of Contents: What Is Pydentic Library? key Features Of Pydentic Library ? Common Use Cases Of Pydentic Library. Examples Of Pydentic Library. (1) What Is Pydentic Library? (2) Validate , Parse & Enforces Type . Validation: Parsing: Enforces Types: (3) Validation Example. from pydantic import BaseModel, EmailStr class User(BaseModel): id: int name: str age: int email: EmailStr Valid Input: valid_data = { "id": 101, "name": "Alice", "age": 28, "email": "[email protected]" } user = User(**valid_data) print(user) Invalid Input: Missing One Parameter valid_data = { "id": 101, "name": "Alice", "email": "[email protected]" } user

    Read More

  • Python ‘argparser’ Library.

    Python ‘argparser’ Library.

    Python ‘argparse’ Library Table Of Contents: What Is An ‘argparse’ Library? Why Do We Use ‘argparse’ Library? Syntax Used In ‘argparse’ Library? Parameters Passed To add_argument() Method. Example Of ‘argparse’ Library? (1) What Is An ‘argparse’ Library? ‘argparse’ library is a command line parsing module used while creating a user-friendly command line interface programming. When you want your program to accept command line arguments from the command prompt, that time you will use ‘argparsr’ library. (2) Why Do We Use ‘argparse’ Library ? To accept command line input as an argument we can use the ‘argparse’ library. By using the

    Read More

  • 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