Skip to main content

16 docs tagged with "python"

View all tags

Arguments

In Python, there are several ways to pass arguments to a function, including positional arguments, keyword arguments, default arguments, variable-length argument lists (args), and variable-length keyword argument dictionaries (*kwargs). The choice of argument passing method depends on the specific requirements of the function and the nature of the data being passed.

Array

In Python, an array is a data structure that stores a collection of elements of the same data type. Unlike lists, which can contain elements of different data types, arrays can only contain elements of a single data type, such as integers, floats, or characters.

Caching Small Integers in Python

Python implements small integer caching as an optimization technique to improve performance and memory usage. Here are the key points about small integer caching in Python:

Comprehensions

In Python, there are several types of comprehensions that can be used to create new data structures from existing ones:

Dependency Injection

Dependency injection is a design pattern commonly used in software engineering that allows for the separation of concerns and promotes code reusability. It is a technique that enables the creation of loosely coupled code, which can be easily tested, maintained, and extended.

Duck Typing

Duck typing is a concept in dynamic programming languages like Python, where the type of an object is determined not by its class name, but by its behavior or the methods and attributes it defines. The term "duck typing" comes from the phrase "if it looks like a duck, swims like a duck, and quacks like a duck, then it probably is a duck."

functools

functools provides a range of features that can greatly simplify your code and make it more efficient. The functools module is part of the Python standard library and provides higher-order functions, decorators, and other utilities for working with functions.

Generator

In Python, a generator is a special type of function that can be used to create iterable sequences of values on-the-fly. Unlike regular functions, which compute and return a value immediately, generators can generate a sequence of values over time, using the yield keyword.

Go vs Python - A Deep Dive into String Length

In the programming world, strings are one of the most common data types. However, different programming languages can have significant differences in how they handle strings. Today, we'll delve into the distinction between Go and Python in processing string lengths, a seemingly simple concept that reveals important differences in language design philosophy.

Itertools

itertools is a powerful Python library that provides a collection of tools for working with iterators and iterable objects. The library is part of the Python standard library, which means that it comes pre-installed with every Python distribution. itertools provides a suite of functions that can help you manipulate and iterate over iterable objects in a more efficient and concise manner. In this article, we'll explore some of the most useful functions in itertools and give some funny examples to help you understand when to use them.

Monkey Patching

In Python programming, monkey patching refers to the practice of modifying or extending the behavior of a module or object at runtime. This technique allows developers to change the behavior of existing code without modifying the original source code. While monkey patching can be a powerful tool, it can also be dangerous if used improperly.

Name Mangling

Name mangling is a feature in Python that is used to avoid naming conflicts in class hierarchies by adding a prefix to the name of a class member that starts with two underscores, but does not end with more than one underscore.

Namedtuple

The namedtuple function is a factory function from the collections module in Python that creates a new class-like object that behaves like a tuple, but with named fields. Here are some cases where you might consider using namedtuple:

Overriding vs. Overloading

Both overriding and overloading are concepts in object-oriented programming that allow you to define methods with the same name but different behavior. However, they differ in their implementation and purpose.

Singleton with Decorator

In Python, a singleton is a design pattern that restricts the instantiation of a class to a single object. A singleton class ensures that only one instance of the class is created and provides a global point of access to that instance.