Articles
(On&)
Docstrings

Docstrings are a type of documentation in Python that describe what a function, class, or module does, and how it should be used. They are written as strings at the beginning of the code block, immediately following the declaration of the function, cla
Docstring formats

There are several docstring formats that are commonly used in Python. Some of the most popular formats include:

    Don't repeat yourself (DRY)

    "Don't repeat yourself" (DRY) is a software development principle that advocates for reducing repetition and redundancy in code. The idea is that if you have duplicate code or logic in your program, you increase the risk of errors and make it harder to maintain and update your code.
    Pass by assignment

    In programming, "pass by assignment" (also called "call by object reference" or "call by sharing") is a way
    Immutable or Mutable

    In Python, objects can be either mutable or immutable.

    An object is considered immutable if its state cannot be modified after it is created. For example, int, float, bool, and tuple are immutable types in Python. Once you create an
    Using context managers

    Context managers are a useful feature in Python that allow you to manage resources, such as files or network connections, in a safe and ef
    The yield keyword

    The yield keyword in Python is used in generator functions to create iterable generators. A generator is a type of iterator t
    Nested contexts

    In Python, a nested context is when one or more context managers are used inside another context manager. This allows you to manage multip
    Two ways to define a context manager

    There are two main ways to define a context manager in Python:

    1. Using a class that implements the context management protocol: This method involves creating a class with __enter__() an
      Handling errors

      In Python, errors can be handled using the try and except statements, which allow you to catch and handle except
      Functions as objects

      In Python, functions are first-class objects, which means they can be treated like any other object, such as an integer, string, or list.
      Functions as variables

      In Python, functions are treated as first-class objects, which means they can be assigned to variables just like any other object. This al
      Lists and dictionaries of functions

      In Python, functions are first-class objects, which means they can be stored in lists and dictionaries just like any other object. This al
      Referencing a function

      In Python, you can reference a function by using its name without parentheses. This is useful when you want to pass a function as an argument to another function, or when you want to assign a function to a variable.

      Functions as arguments

      In Python, functions can be passed as arguments to other functions. This is known as higher-order functions, and it allows for a powerful and flexible programming paradigm. Here's an example:


      Defining a function inside another function

      n Python, it is possible to define a function inside another function. This is known as a nested function or an inner function. Here is an example:

      Functions as return values

      In Python, functions can also be used as return values. This is useful for creating functions that generate other functions based on some input. Here's an example:

      The global keyword

      In Python, the global keyword is used to declare a variable as global, which means it can be accessed and modified from any part of the program.

      When a variable is defined inside a function,
      The nonlocal keyword

      Built-in Functions

      Enjoyed this article? Share it!