Python A to Z [Step by Step Short Question for Python]

python A to Z

python A to Z

 ABC

Abstract Base Class. A class that cannot be instantiated, only subclassed. ABCs are how interfaces are formalized in Python. Instead of inheriting from an ABC, a class may also declare that it fulfills the interface by registering with the ABC to become a virtual subclass.

 Accessor

A method implemented to provide access to a single data attribute. Some authors use acessorios a generic term encompassing getter and setter methods, others use it to refer only to getters, referring to setters as mutators.

 Aliasing

Assigning two or more names to the same object. For example, in a = []; b = athe variables a and b are aliases for the same list object. Aliasing happens naturally all the time in any language where variables store references to objects. To avoid confusion, just forget the idea that variables are boxes that hold objects (an object can’t be in two boxes at the same time). It’s better to think of them as labels attached to objects (an object can have more than one label).

 Argument

An expression passed to a function when it is called. In Pythonic parlance, argument and parameter are almost always synonyms. See parameter for more about the distinction and usage of these terms.

 Attribute

Methods and data attributes (i.e. “fields” in Java terms) are all known as attributes in Python. A method is just an attribute that happens to be a callable object (usually a function, but not necessarily).

BDFL

Benevolent Dictator For Life, alias for Gui‐do van Rossum, creator of the Python language.

binary sequence

Generic term for sequence types with byte elements. The built-in binary sequence types are byte, bytearrayand memoryview.

BOM

Byte Order Mark, a sequence of bytes that may be present at the start of an UTF-16 encoded file. A BOM is the character U +FEFF (ZERO WIDTH NO-BREAK SPACE) encoded to produce either b’\xfe\xff’ on a big-endian CPU, or b’\xff\xfe’on a littleendian one. Since there is no U+FFFE characer in Unicode, the presence of these bytes unambiguously reveals the byte ordering used in the encoding. Although redundant, a BOM encoded as b’\xef\xbb\xbf’ may be found in UTF-8 files.

bound method

A method that is accessed through an instance becomes bound to that instance. Any method is actually a descriptor and when accessed, it returns itself wrapped in an object that binds the method to the instance. That object is the bound method. It can be invoked without passing the value of self.

          For example, given the assignment my_method = my_obj.method, the bound method can later be called as my_method(). Contrast with unbound method.

built-in function

A function bundled with the Python interpreter, coded in the underlying implementation language (i.e. C, for CPython; Java, for Jython and so on). Built-in Functions. But built-in modules like sys, math, reetc. also contain built-in functions.

byte string

An unfortunate name still used to refer to bytes or byte array in Python 3. In Python 2, the strtype was really a byte string, and the term made sense to distinguish str from unicode strings. In Python 3 it makes no sense to insist on this term, and I tried to use byte sequence whenever I needed to talk in general about… byte sequences.

bytes-like object

A generic sequence of bytes. The most com mon bytes-like types are bytes, byte array and memory view are but other objects supporting the low-level C Python buffer protocol also qualify, if their elements are single bytes.

callable object

An object that can be invoked with the call operator (), to return a result or to perform some action. There are seven flavors of callable objects in Python: user-defined functions, built-in functions, built-in methods, instance methods, generator functions, classes and instances of classes that implement the __call__special method.

CamelCase

The convention of writing identifiers by joining words with upper cased initials, for example: ConnectionRefusedError. PEP-8 recommends class names should be written in CamelCase, but the advice is not fol‐
lowed by the Python standard library. See snake_case.

Cheese Shop

Original name of the Python Package Index (PyPI), after the Monty Python skit about a cheese shop where nothing is available. The alias https://cheeseshop.python.org/ still works, as of this writing. See PyPI.

class

A program construct defining a new type, with data attributes and methods specifying possible operations on them.

code point

An integer in the range 0 to 0x10FFFF used to identify an entry in the Unicode character database. As of Unicode 7.0, less than 3% of all code points are assigned to characters. In the Python documentation, the term may be spelled as one or two words.

code smell

A coding pattern which suggests there may be something wrong with the design of a program. For example, excessive use of isinstance checks against concrete classes is a code smell, as it makes the program harder to extend to deal with new types in the future.

codec

(encoder/decoder) A module with functions to encode and decode, usually from strto bytes and back, although Python has a few codecs that perform bytes to bytes and str to str transformations.

collection

Generic term for data structures made of items that can be accessed individually. Some collections can contain objects of arbitrary types (see container) and others only objects of a single atomic type (see flat sequence). list and bytes are both collections, but list is a container, and bytes is a flat sequence.

considered harmful

Edsger Dijkstra’s letter titled “Go To Statement Considered Harmful” established a formula for titles of essays criticizing some computer science technique. The English language Wikipedia has an Considered_harmful article listing several examples, including “Considered Harmful” Es‐says Considered Harmful by Eric A. Meyer.

constructor

Informally, the __init__instance method of a class is called its constructor, since its semantics is similar to that of a Java constructor. However, a fitting name for __init__is initializer, since it does not actually build the instance, but receives it as its self argument. The constructor term better describes the __new__class method, which Python calls before __init__, and is responsible for actually creating and instance and returning it.

container

An object that holds references to other objects. Most collection types in Python are containers, but some are not. Contrast with flat sequence, which are collections but not containers.

context manager

An object implementing both the __enter__and __exit__special methods, for use in a with block.

coroutine

A generator used for concurrent programming by receiving values from a scheduler or an event loop via coro.send(value). The term may be used to describe the generator function or the generator object obtained by calling the generator function.

CPython

The standard Python interpreter, implemented in C. This term is only used when discussing implementation-specific behavior, or when talking about the multiple Python interpreters available, such as PyPy.

CRUD

Acronym for Create, Read, Update and Delete, the four basic functions in any application that stores records.

decorator

A callable object A that returns another callable object Band is invoked in code using the syntax @A right before the definition of a callable C. When reading such code, the Python interpreter invokes A(C)and binds the resulting Bto the variable previously assigned to C, effectively replacing the definition of C with B. If the target callable Cis a function, then A is a function decorator; if Cis a class, then A is a class decorator.

deep copy

A copy of an object in which all the objects that are attributes of the object are themselves also copied. Contrast with shallow copy.

descriptor

A class implementing one or more of the__get__, __set__or __delete__ special methods becomes a descriptor when one of its instances is used as a class attribute of another class, the managed class. Descriptors manage the access and deletion of managed attributes in the managed class, often storing data in the managed instances.

docstring

Short for documentation string. When the first statement in a module, class or function is a string literal, it is taken to be the docstring for the enclosing object, and the interpreter saves it as the __doc__attribute of that object.

doctest

A module with functions to parse and run examples embedded in the docstrings of Python modules or in plain text files. May also be used from the command line as: python -m doctest module_with_tests.py.

DRY

Don’t Repeat Yourself— a software engineering principle stating that “Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.” It first appeared in the book The Pragmatic Programmer by Andy Hunt and Dave Thomas (Addison-Wesley, 1999).

duck typing

A form of polymorphism where functions operate on any object that implements the appropriate methods, regardless of their classes or explicit interface declarations.

dunder

Shortcut to pronounce the names of special methods and attributes that are written with leading and trailing double-underscores (i.e. __len__is read as “dunder len”).

EAFP

Acronym standing for the quote “It’s easier to ask forgiveness than permission”, attributed to computer pioneer Grace Hopper, and quoted by Pythonistas referring to dynamic programming practices like accessing attributes without testing first if they exist, and then catching the exception when that is the case. The docstring for the has attr function actually says that it works “by calling getattr(object, name) and catching AttributeError”.

eager

An iterable object that builds all its items at once. In Python, a list comprehension is eager. Contrast with lazy.

fail-fast

A systems design approach recommending that errors should be reported as early as possible. Python adheres to this principle more closely than most dynamic languages. For example, there is no “undefined” value: variables referenced before initialization generate an error, and my_dict[k]raises an exception if k is missing (in contrast with JavaScript). As another example, parallel assignment via tuple unpacking in Python only works if every item is explicitly handled, while Ruby silently deals with item count mismatches by ignoring unused items on the right side of the =, or by as‐signing nil to extra variables on the left side.

falsy

Any value x for which bool(x) returns False; Python implicitly uses bool to evaluate objects in boolean contexts, such as the expression controlling an ifor while loop. The opposite of truthy.

file-like object

Used informally in the official documentation to refer to objects implementing the file protocol, with methods such as read, write, close etc. Common variants are text files containing encoded strings with lineoriented reading and writing, StringIO instances which are in-memory text files, and binary files, containing unencoded bytes.

first-class function

Any function that is a first-class object in the language, i.e. can be created at run time, assigned to variables, passed as an argument, and returned as the result of another function. Python functions are first-class functions.

flat sequence

A sequence type that physically stores the values of its items, and not references to other objects. The built-in types str, bytes, byte array, memory viewand array.array are flat sequences. Contrast with list, tuple and collections.deque which are container sequences.

function

Strictly, an object resulting from evaluation of a def block or a lambda expression. Informally, the word function is used to describe any callable object, such as methods and even classes sometimes. The official Built-in Functions list includes several built-in classes like dict, range and str.

generator

An iterator built with a generator function or a generator expression that may produce values without necessarily iterating over a collection; the canonical example is a generator to produce the Fibonacci series which, because it is infinite, would never fit in a collection. The term is sometimes used to describe a generator function, besides the
object that results from calling it.

generator function

A function that has the yield keyword in its body. When invoked, a generator function returns a generator.

generator expression

An expression enclosed in parenthesis using the same syntax of a list comprehension, but returning a generator instead of a list. A generator expression can be understood as a lazy version of a list comprehension.

generic function

a group of functions designed to implement the same operation in customized ways for
different object types. As of Python 3.4, the functools. single dispatch decorator the standard way to create generic functions. This is known as multimethods in other languages.

GoF book

Alias for Design Patterns: Elements of Reusable Object-Oriented Software (Addison Wesley, 1995), authored by the so-called Gang of Four (GoF): Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides.

hashable

An object is hashable if it has both __hash__and __eq__methods, with the constraints that the hash value must never change and if a == b then hash(a) == hash(b) must also be True. Most immutable built-in types are hashable, but a tuple is only hashable if every one of its items is also hashable.

higher-order function

A function that takes another function as argument, like sorted, map and `filter, or a function that returns a function as result, as Python decorators do.

idiom

“A manner of speaking that is natural to native speakers of a language”, according to the Princeton WordNet.
import time The moment of initial execution of a module when its code is loaded by the Python interpreter, evaluated from top to bottom and compiled into bytecode. This is when classes and functions are defined and be‐
come live objects. This is also when decorators are executed.

initializer

A better name for the __init__ method (instead of constructor). Initializing the instance received as self is the task of __init__. Actual instance construction is done by the __new__method. See constructor.

iterable

Any object from which the iter built-in function can obtain an iterator. An iterable object works as the source of items in for loops, comprehensions and tuple unpacking. Objects implementing an __iter__ method returning an iterator are iterable.Sequences are always iterable; other objects implementing a __getitem__method may
also be iterable.

iterable unpacking

A modern, more precise synonym for tuple unpacking. See also parallel assignment.

iterator

Any object that implements the __next__no-argument method which returns the next item in a series, or raises Stop Iteration when there are no more items. Python iterators also implement the __iter__ method so they are also iterable. Classic iterators, according to the original design pattern, return items from a collection. A generator is also an iterator, but it’s more flexible.

KISS principle

The acronym stands for “Keep It Simple, Stupid”. This calls seeking the simplest possible solution, with the fewest moving parts. The phrase was coined by Kelly Johnson, a highly accomplished aerospace engineer who worked in the real Area 51 designing some of the most advanced aircraft of the 20th century.

lazy

An iterable object which produces items on demand. In Python, generators are lazy.

list comprehension

An expression enclosed in brackets that uses the for and in keywords to build a list by processing and filtering the elements from one or more iterables. A list comprehension works eagerly.

liveness

An asynchronous, threaded or distributed system exhibits the liveness property when “something good eventually happens”, i.e. even if some expected computation is not happening right now, it will be completed eventually. If a system deadlocks, it has lost its liveness.

managed attribute

A public attribute managed by a descriptor object. Although the managed attribute is defined in the managed class, it operates like an instance attribute, i.e. it usually has a value per instance, held in a storage attribute. See descriptor.

managed class

A class that uses a descriptor object to manage one of its attributes. See descriptor.

managed instance

An instance of a managed class. See managed attribute` and descriptor.

metaclass

A class whose instances are classes. By default, Python classes are instances of type, for example, type(int)is the class type,therefore type is a metaclass. User-defined metaclasses can be created by subclassing type.

metaprogramming

The practice of writing programs the use run-time information about themselves to change their behavior. For example, an ORM may introspect model class declarations to figure determine how to validate database record fields and convert database types to Python types.

monkey patching

Dynamically changing a module, class or function at run time, usually to add features or fix bugs. Because it is done in memory and not by changing the source code, a monkey patch only affects the currently running instance of the program. Monkey patches break encapsulation and tend to be tightly coupled to the implementation details of the patched code units, so they are seen as temporary work-arounds and not a recommended technique for code integration.

mixin class

A class designed to be subclassed together with one or more additional classes in a multiple-inheritance class tree. A mixin class should never be instantiated, and a concrete subclass of a mixin class should also subclass another non-mixin class.

mixin method

A concrete method implementation provided in an ABC or in a mixin class.

name mangling

The automatic renaming of private attributes from __xto _MyClass__x, per‐ formed by the Python interpreter at run‐time.

non-overriding descriptor

A descriptor that does not implement __set__and therefore does not interfere with setting of the managed attribute in the managed instance. Consequently, if a namesake attribute is set in the managed instance, it will shadow the descriptor in that instance. Also called non-data descriptor or shadow able descriptor. Contrast with overriding descriptor.

ORM

Object-Relational Mapper— an API that provides access to database tables and records as Python classes and objects, providing method calls to perform database operations. SQLAlchemy is a popular stand-alone Python ORM; the Django and Web2py frameworks have their own bundled ORMs.

overriding descriptor

A descriptor that implements __set__ and therefore intercepts and overrides attempts at setting the managed attribute in the managed instance. Also called data descriptor or enforced descriptor. Contrast with nonoverriding descriptor.

parallel assignment

Assigning to several variables from items in an iterable, using syntax like a, b = [c, d]— also known as destructuring assignment. This is a common application of tuple unpacking.

parameter

Functions are declared with 0 or more “formal parameters”, which are unbound local variables. When the function is called, the arguments or “actual parameters” passed are bound to those variables. In this book I tried to use argument to refer to an actual parameter passed to a function, and parameter for a formal parameter in the function declaration. However, that is not always feasible because the terms parameter and argumentare use interchangeably all over the Python docs and API. See argument.

prime (verb)

Calling next(coro)on a coroutine to advance it to its first yield expression so that it becomes ready to receive values in succeeding coro.send(value)calls.

PyPI

The Python Package Index at https://pypi.python.org/where more than 49.000 packages are available. A.k.a. the Cheese shop(which see). PyPI is pronounced as “pie-P-eye” to avoid confusion with PyPy.

PyPy

An alternative implementation of the Python programming language using a toolchain that compiles a subset of Python to machine code, so the interpreter source code is actually written in Python. PyPy also includes a JIT to generate machine code for user programs on the fly— like the Java VM does. As of November, 2014, PyPy is 6.8 times faster than CPython on average, according to published benchmarks. PyPy is pronounced as “pie-pie” to avoid confusion with PyPI.

Pythonic

Used to praise idiomatic Python code, which makes good use of language features to be concise, readable and often faster as well. Also said of APIs that enable coding in a way that seems natural to proficient Python programmers. See idiom.

refcount

The reference counter that each CPython object keeps internally in order to determine when it can be destroyed by the garbage collector.

referent

The object that is the target of a reference. This term is most often used to discuss weak references.

REPL

Read-eval-print-loop, an interactive console, like the standard python or alternatives like ipython, b python and Python Anywhere.

sequence

Generic name for any iterable data structure with a known size and (eg. len(s)) and allowing item access via 0-based integer indexes (eg. s[0]). The word sequence has been part of the Python jargon from the start, but only with Python 2.6 it was formalized as an abstract class in collections.abc.Sequence.

serialization

Converting an object from its in-memory structure to a binary or text oriented format for storage or transmission, in a way that allows the future reconstruction of a clone of the object on the same system or on a different one. The pickle module supports serialization of arbitrary Python objects to a binary format.

shallow copy

A copy of an object which shares references to all the objects that are attributes of the original object. Contrast with deep copy.

singleton

An object that is the only existing instance of a class— usually not by accident but because the class is designed to prevent creation of more than one instance. There is also a design pattern named Singleton, which is a recipe for coding such classes. The None object is a singleton in Python.

slicing

Producing a subset of a sequence by using the slice notation, e.g. my_sequence[2:6]. Slicing usually copies data to produce a new object; in particular, my_sequence[:] creates a shallow copy of the entire sequence. But a memory view object can be sliced to produce a new memory view which shares data with the original object.

snake_case

The convention of writing identifiers by joining words with the underscore character _, for example: run_until_complete. PEP-8 calls this style “lowercase with words separated by underscores” and recommends it for naming functions, methods, arguments and variables. For packages, PEP-8 recommends concatenating words with no separators. The Python standard library has many examples of snake_case identifiers, but also many examples of identifiers with no separation between words, e.g. getattr, classmethod, isinstance, str.ends with etc. See CamelCase.

special method

A method with a special name such as __ge titem__, spelled with leading and trailing double underscores. Almost all special methods recognized by Python are described in the Data Model chapter of the Python Language Reference, but a few that are used only in specific contexts are documented in other parts of the documentation. For example the __missing__ method of mappings is mentioned in the dict section of the Built-in Types page in the Standard Library documentation.

storage attribute

An attribute in a managed instance used to store the value of an attribute managed by a descriptor. See also managed attribute.

strong reference

A reference that keeps an object alive in Python. Contrast with weak reference.

tuple unpacking

Assigning items from an iterable object to a tuple of variables, for example: first, second, third == my_list. This is the usual term used by Pythonistas, but iterable unpacking is gaining traction.

truthy

Any value x for which bool(x) returns True; Python implicitly uses bool to evaluate objects in boolean contexts, such as the expression controlling an ifor while loop. The opposite of falsy.

type

Each specific category of program data, defined by a set of possible values and operations on them. Some Python types are close to machine data types (e.g. float and bytes) while others are extensions (e.g. int is not limited to CPU word size, str holds multi-byte Unicode data points) and very high-level abstractions (e.g. dict, deque etc.). Types may be user defined or built into the interpreter (a “built-in” type). Before the watershed type/class unification in Python 2.2, types and classes were different entities, and user-defined classes could not extend built-in types. Since then, built-in types and new-style classes became compatible, and a class is an instance of type. In Python 3 all classes are new-style classes.

unbound method

An instance method accessed directly on a class is not bound to an instance, therefor it’s said to be an “unbound method”. To succeed, a call to an unbound method must explicitly pass an instance of the class as the first argument. That instance will be as signed to the self argument in the method.

uniform access principle

Bertrand Meyer, creator of the Eiffel Language, wrote: “All services offered by a module should be available through a uniform notation, which does not betray whether they are implemented through storage or through computation”. Properties and descriptors allow the implementation of the uniform access principle in Python. The lack of a new operator, making function calls and object instantiation look the same, is another form of this principle: the caller does not need to know whether the invoked object is a class, a function or any other callable.

user-defined

Almost always in the Python docs the word user refers to you and I— programmers who use the Python language— as opposed to the developers who implement a Python interpreter. So the term “user-defined class” means a class written in Python, as opposed to built-in classes written in C, like str.

virtual subclass

A class that does not inherit from a super‐class but is registered using TheSuperClass.register(TheSubClass). A misfeature of the language. Andrew Kushling’s famous post “Python warts” has been acknowledged by the BDFLas influential in the decision to break backwards compatibility in the design of Python 3, since most of the failings could not be fixed otherwise. Many of Kushling’s issues were fixed in Python 3.

weak reference

A special kind of object reference that does not increase the referent object reference count. Weak references are created with one of the functions and data structures in the weakref module.

YAGNI

“You Ain’t Gonna Need It”, a slogan to avoid implementing functionality that is not immediately necessary based on assumptions about future needs.

Zen of Python

type import this into any Python console since version 2.2.


Also published on Medium.

Leave a Reply