Appendix A. Glossary 110 Python Tutorial, Release 3.9.5 The same concept exists for classes, but is less commonly used there. See the documentation for function definitions and class definitions for more about decorators. descriptor Any object which defines the methods$_{__get__()}$ ,$_{__set__()}$ , or$_{__delete__()}$ . When a class attribute is a descriptor, its special binding behavior is triggered upon attribute lookup. Normally, using a.b to get, set or delete an attribute looks up the object named b in the class dictionary for a , but if b is a descriptor, the respective descriptor method gets called. Understanding descriptors is a key to a deep understanding of Python because they are the basis for many features including functions, methods, properties, class methods, static methods, and reference to super classes. dictionary An associative array, where arbitrary keys are mapped to values. The keys can be any object with __hash__() and$_{__eq__()}$ methods. Called a hash in Perl. dictionary comprehension A compact way to process all or part of the elements in an iterable and return a dic- tionary with the results. results = {n: n ** 2 for n in range(10)} generates a dictionary containing key n mapped to value n ** 2 . See comprehensions. dictionary view The objects returned from$_{dict.keys()}$ ,$_{dict.values()}$ , and$_{dict.items()}$ are called dictionary views. They provide a dynamic view on the dictionary’s entries, which means that when the dic- tionary changes, the view reflects these changes. To force the dictionary view to become a full list use list(dictview) . See dict-views. docstring A string literal which appears as the first expression in a class, function or module. While ignored when the suite is executed, it is recognized by the compiler and put into the$_{__doc__}$ attribute of the enclosing class, function or module. Since it is available via introspection, it is the canonical place for documentation of the object. duck-typing A programming style which does not look at an object’s type to determine if it has the right interface; instead, the method or attribute is simply called or used (“If it looks like a duck and quacks like a duck, it must be a duck.”) By emphasizing interfaces rather than specific types, well-designed code improves its flexibility by allowing polymorphic substitution. Duck-typing avoids tests using$_{type()}$ or$_{isinstance()}$ . (Note, however, that duck-typing can be complemented with abstract base classes .) Instead, it typically employs hasattr() tests or EAFP programming. EAFP Easier to ask for forgiveness than permission. This common Python coding style assumes the existence of valid keys or attributes and catches exceptions if the assumption proves false. This clean and fast style is characterized by the presence of many$_{try}$ and$_{except}$statements. The technique contrasts with the LBYL style common to many other languages such as C. expression A piece of syntax which can be evaluated to some value. In other words, an expression is an accumulation of expression elements like literals, names, attribute access, operators or function calls which all return a value. In contrast to many other languages, not all language constructs are expressions. There are also statement s which cannot be used as expressions, such as$_{while}$. Assignments are also statements, not expressions. extension module A module written in C or C++, using Python’s C API to interact with the core and with user code. f-string String literals prefixed with$_{'f'}$ or$_{'F'}$ are commonly called “f-strings” which is short for formatted string literals. See also PEP 498 . file object An object exposing a file-oriented API (with methods such as$_{read()}$ or$_{write()}$ ) to an underlying resource. Depending on the way it was created, a file object can mediate access to a real on-disk file or to another type of storage or communication device (for example standard input/output, in-memory buffers, sockets, pipes, etc.). File objects are also called file-like objects or streams . file-like object A synonym for file object . finder An object that tries to find the loader for a module that is being imported. There are actually three categories of file objects: raw binary files , buffered binary files and text files . Their interfaces are defined in the$_{io}$ module. The canonical way to create a file object is by using the$_{open()}$ function. Since Python 3.3, there are two types of finder: meta path finders for use with$_{sys.meta_path}$ , and path entry finders for use with$_{sys.path_hooks}$ . For more information about descriptors’ methods, see descriptors or the Descriptor How To Guide.