What you will learn in Python How-To
63 techniques to improve your Python code
Chapter by chapter
Concepts explained in this book
- classA class is a programming-language construct that defines a type’s structure or behavior and provides a basis for creating or representing objects.
- functionA function is a defined operation that maps inputs to outputs and, when implemented as a callable program unit, may also produce effects.
- objectInstantiation is the process of creating an instance of a class.
- default valueA default value is a value automatically used for a function parameter when the corresponding argument is not explicitly supplied.
- MapA map is an associative data structure that stores key-value pairs and supports retrieving values by key.
- listA list is an ordered collection of elements arranged in a sequence.
- attributeAn attribute is a named value or behavior associated with a Python object and accessible through attribute access.
- iterableAn iterable is an object or value that provides or supports a protocol for producing its elements sequentially.
- code readabilityReadability is the degree to which source code or textual information can be readily understood by human readers.
- exceptionException is the standard Python base class for ordinary application exceptions that should generally be catchable without intercepting system-exiting conditions.
- regular expressionA regular expression pattern is a textual specification describing character sequences and structural conditions to be matched in text.
- constructor method__init__ is a Python instance-initialization method that runs when an object is created and establishes its initial state.
- iteratorAn iterator is an object that produces successive items through Python's iteration protocol.
- f-stringAn f-string is a string literal syntax that evaluates embedded expressions and formats their values within the string.
- loopA while loop repeatedly executes a block of code while a Boolean condition remains true.
- tupleA tuple is an ordered, immutable collection of values that can represent a fixed set of fields.
- setA set is a Python collection of distinct elements without a defined positional order.
- decoratorA decorator is a callable that modifies or extends the behavior of another callable or class without changing its underlying definition.
- data modelA data model is a structured representation of the entities, attributes, and relationships in an application domain.
- monitoringLogging is the recording of program events and diagnostic information through a structured message mechanism.
- data structureA data structure is an organized representation of data together with the operations or access patterns associated with that representation.
- type hintsType hinting is the practice of annotating Python variables, parameters, or return values with their intended types without generally enforcing those types at runtime.
- maintainabilityMaintainability is the degree to which software can be understood, modified, corrected, or extended with reasonable effort.
- superclassA superclass is a class whose attributes and behavior can be inherited by a more specialized subclass.
- file objectA file is a persistent, named container of data stored by a computer system.
- enumEnumeration is the technique of associating each item in a set of related concepts with a distinct named member of a common category.
- zipzip is a Python built-in function that returns an iterator of tuples combining corresponding elements from multiple iterables.
- tuple unpackingUnpacking is the technique of retrieving the individual items of an iterable and assigning them to corresponding variables.
- comprehensionA list comprehension is Python syntax for constructing a list by iterating over an iterable and optionally filtering or transforming its items.
- docstringA docstring is a string literal associated with a module, class, or function that documents its purpose, parameters, return value, or other behavior.
- testA test case is a defined set of inputs, execution conditions, and expected results for evaluating software behavior.
- task classThe Task class is a book-specific Python class representing an individual task with task data and persistence behavior.
- immutable collectionImmutability is the property of a data structure or object whose contents cannot be changed after creation.
- positional argumentA positional argument is a function argument whose value is associated with a parameter according to its position in the call.
- initializerA constructor is a callable that creates an instance of a class or other typed object.
- try-catch statementA try-catch statement is a control-flow construct that executes code under exception handling and transfers control to a matching handler when an exception is raised.
- dataclassA data class is a Python class whose declared attributes are treated as fields and for which common methods such as a constructor can be generated automatically.
- LoggerA logger is an object in a logging system that creates log records and applies a severity threshold before forwarding them to handlers.
- static methodA static method is a method defined on a class that does not receive an instance or class reference implicitly and operates independently of instance state.
- return valueThe value produced by a function call, either explicitly by a return statement or implicitly when execution reaches the end of the function.
- idiomatic coding stylePythonic is an idiomatic style of writing Python code that follows the language's conventions and emphasizes clear, concise solutions.
- methodA method is a function defined as an attribute of a class and intended to operate on instances or the class itself.
- else clauseAn else clause is an optional part of a Python try...except statement that runs when the protected try clause completes without raising an exception.
- StreamlitStreamlit is an open-source Python library for building interactive data applications and web interfaces from Python scripts.
- copyObject copying is the technique of creating a separate object representation from an existing object.
- stack traceA traceback is a diagnostic report showing the sequence of active calls and execution context when an exception occurs.
- picklePickling is Python's serialization process for converting objects into a byte stream that can be stored and later reconstructed.
- conditional logicConditional logic is a programming technique that selects execution paths, actions, or result values according to evaluated conditions.
- __str____str__ is a Python special method that returns an informal, user-oriented string representation of an object.
- inheritanceClass inheritance is a Python object-model feature in which a class derives attributes and behavior from one or more other classes.
- idid is a Python built-in function that returns an integer identifying an object during its lifetime.
- named tupleA named tuple is an immutable tuple-like data structure whose elements can be accessed by descriptive field names as well as by position.
- virtual environmentA virtual environment is an isolated directory tree containing a Python installation and project dependencies that are separate from the computer's other installations.
- inner functionA nested function is a function defined within the body of another function.
- SQLiteSQLite is an embedded relational database engine that stores an application's data in a local disk file without requiring a separate server process.
- higher-order functionA higher-order function is a function that accepts functions as arguments, returns functions, or both.
- logging moduleThe logging module is Python's standard-library module for recording application events through loggers, handlers, formatters, and severity levels.
- closureA closure is a function that retains access to variables from its enclosing lexical scope after that scope has finished executing.
- **kwargskwargs is the conventional parameter name for a dictionary that collects variable-length keyword arguments passed to a Python function.
- lambdaThe lambda keyword introduces a Python expression that defines an anonymous function.
- NoneNone is Python's singleton value representing the absence of a meaningful result or value.
- sorting algorithmSorting is the process of arranging elements into an order determined by a comparison or key function.
- generatorA generator is a Python construct that produces a sequence of values incrementally through iteration rather than computing the entire sequence at once.
- selfSelf is a typing construct that denotes the enclosing class and the type of instances or class-level results associated with it.
- PythonPython is a high-level programming language with dynamic semantics and extensive support for readable application code.
- namespaceA global namespace is the module-level namespace that maps identifiers to their corresponding objects.
- callablecallable is a Python built-in function that returns whether an object can be invoked with the call operator.
- break statementA break statement immediately terminates the innermost enclosing loop.
- variadic argumentsargs is the conventional parameter name for a function parameter that collects a variable-length sequence of positional arguments.
- lazy initializationA lazy attribute is an attribute whose value is computed only when the attribute is accessed rather than when its object is initialized.
- logging levelA logging level is a severity classification that determines which log records a logger or handler processes.
- LEGBThe LEGB rule is Python's name-resolution rule that searches local, enclosing-function, global, and built-in scopes in that order.
- JSONJSON is a lightweight text-based data interchange format that represents structured values using objects, arrays, strings, numbers, booleans, and null.
- floating-point arithmeticA floating-point number is a numeric representation for values that may contain a fractional component and use finite precision.
- file operationA file operation is a programmatic action that manipulates files, such as moving, copying, extracting, or identifying them by modification time.
- with statementA with statement is Python syntax that manages a context-bound operation and invokes the context manager's cleanup behavior when the block exits.
- static fieldA class attribute is an attribute stored on a Python class and available to instances through attribute lookup when no instance-specific value overrides it.
- scopeA scope is a region of Python code that defines the visibility boundary for names and the namespace associated with them.
- __dict____dict__ is the dictionary attribute that stores an object's or class's dynamically assigned attributes when such a dictionary is available.
- memory locationA memory address is a location in computer memory associated with an object while it exists.
- return statementA return statement terminates a function and optionally supplies a return value to its caller.
- user-defined exceptionA custom exception is a programmer-defined exception type used to represent application-specific error conditions.
- findThe Python str.find method returns the lowest index at which a specified substring occurs, or -1 if it is absent.
- __new____new__ is Python's special class-level method that creates and returns a new instance before initialization.
- nextAn iterator operation that advances an iterator and returns its next value or result, with behavior on exhaustion determined by the API.
- named argumentA keyword argument is a function argument supplied by associating an explicit parameter name with its value.
- CSVA CSV file is a text file that represents tabular data with records and fields separated according to comma-separated-value conventions.
- hashableA hashable object is a Python object with a stable hash value and equality behavior that allow it to serve as a dictionary key or set element.
- deep copyA deep copy is a copied object whose interior objects are recursively copied so that mutable objects are not shared with the original.
- openopen is a Python built-in function that opens a file and returns a file object for reading, writing, or other supported operations.
- __repr____repr__ is a Python special method that returns an official, unambiguous string representation of an object, ideally one that can recreate an equivalent object when evaluated as code.
- string modulestring is a Python standard-library module providing constants and utilities for common string character sets and operations.
- slicingSlicing selects or partitions a portion of an indexed sequence or multidimensional array, often along specified indices or dimensions.
- data conversionData conversion is the transformation of a value or data from one type, format, or representation to another, explicitly or implicitly.
- string formattingFormat-based string formatting is the method of producing strings from a format string and supplied values through formatting operations.
- class methodA class method is a method associated with a class that receives the class as its first argument and can access class-level state and behavior.
- csv.readercsv.reader is a Python standard-library factory that creates an iterator for parsing delimited text rows into sequences of fields.
- global statementThe global keyword declares that assignments to a name in a function refer to the corresponding binding in the global scope.
- debuggerA debugger is an interactive software tool for pausing program execution, inspecting program state, and controlling execution while diagnosing defects.
- directory structureA project folder structure is an organized arrangement of directories and files that groups related source artifacts within a software project.
- refactoringRefactoring is the restructuring of existing code to improve its design or maintainability without changing its externally observable behavior.
- debuggingDebugging is the process of locating, diagnosing, and correcting defects in software.
- splitSplit is a regular-expression method that divides a string at occurrences of matched patterns, optionally limiting the number of divisions.
- protected memberProtected access is an access level in which a class attribute or method is available to the defining class and its subclasses but not external code.
- reversingThe reverse method is a Python list method that reverses a list in place and returns None.
- keyword-only parameterA keyword-only argument is a function argument that must be supplied by explicitly naming its parameter rather than by position.
- integerint is Python's built-in numeric type for representing integers and the callable that constructs such values.
- format stringA format specifier is the portion of a formatting expression that controls how a value is represented, such as its precision or alignment.
- performancePerformance is the measured efficiency or speed with which a program or function processes data and responds to requests.
- private memberA private method is a class method intended for internal use whose name or access convention discourages or restricts direct access by callers.
- side effectA side effect is an observable state change produced by evaluating or calling an operation in addition to its returned result.
- web applicationA web application is software whose user interface and functionality are accessed through web technologies and a browser.
- handlerA handler is a logging component that processes records emitted by a logger, typically by writing them to a destination.
- data transformationA data transformation is an operation or function that maps input data or its representation to modified data or a different representation.
- global variableA global variable is a variable defined in a module's global scope and accessible according to the language's name-resolution rules.
- read operationread is a file-object method that retrieves a specified number of characters or the remaining contents of a file as text or bytes.
- reference countingReference counting is an automatic memory-management technique that tracks how many references identify each object and releases an object when its count reaches zero.
- isinstanceisinstance is a Python built-in function that tests whether an object is an instance of a specified class or tuple of classes, including subclasses.
- file pathA file path is a textual or structured identifier specifying the location of a file or directory in a filesystem.
- text alignmentText alignment is the positioning of textual values within a specified width, such as left, right, or center positioning.
- continue statementA continue statement skips the remaining body of the current loop iteration and proceeds to the next iteration when one exists.
- FileHandlerFileHandler is a Python logging handler class that writes log records to a file.
- pickle formatA pickle file is a persistent serialized representation of Python objects produced by the pickle protocol.
- unpicklingUnpickling is the process of deserializing a pickle representation to recreate the Python object it contains.
- dict.getThe get method is a dictionary operation that retrieves a value for a key while returning a default or None instead of raising an exception for a missing key.
- key parameterA key parameter is a sorting or selection parameter that accepts a callable for deriving a comparison value from each item.
- context managerA context manager is an object or protocol that manages entry into and exit from a resource-handling context, including cleanup when the context ends.
- hash functionHashing is the computation of a compact hash value from input data using a hash function.
- except blockAn except clause is the handler block within a Python try...except statement that executes when a matching exception is raised in the protected try clause.
- execution context stackA call stack is a runtime structure that records active and underlying function or method calls in execution order.
- finallyA finally clause is a block in an exception-handling construct that executes after the associated try or exception-handling clauses, including when control leaves them with a return statement.
- enumerateThe enumerate function is a Python built-in function that returns an iterator producing position-and-item pairs from an iterable.
- NameErrorNameError is the Python exception raised when a referenced name cannot be found in the applicable namespaces.
- zip objectA zip object is an iterator that yields tuples containing corresponding items from aligned input iterables.
- concatenationString joining is the operation of combining multiple strings into one string with an optional separator.
- overrideMethod overriding is the object-oriented technique in which a subclass defines a method with the same name as an inherited method to provide a specialized implementation.
- single-task functionA single-purpose function is a function whose operations serve one clearly defined responsibility.
- filteringFiltering is the technique of retaining only the items in a collection that satisfy a specified condition.
- breakpointA breakpoint is a designated execution point at which a program pauses so its state can be examined during debugging.
- pdbpdb is Python's standard-library source-code debugger and interactive debugging interface.
- set operationA set operation is an operation that combines, compares, or otherwise transforms sets according to their element membership.
- unhashableAn unhashable object is a Python object that cannot serve as a dictionary key or set element because it lacks the required stable hashability.
- sessionSession state is per-session storage that preserves application data across reruns of a web application script.
- assertEqualassertEqual is a unittest assertion method that checks whether two values are equal and reports a test failure otherwise.
- widgetA widget is a self-contained user-interface component that displays information or provides an interaction.
- string conversionA string representation is textual output that describes the value or identity of an object.
- joinThe Python str.join method returns one string by concatenating the elements of an iterable with the calling string inserted between adjacent elements.
- is operatorThe identity operator is tests whether two references designate the same object.
- bindingName binding is the association of an identifier with the program entity or value it denotes.
- TestCaseTestCase is the unittest base class that provides structure and assertion methods for individual test cases.
- fieldfield is a dataclass-module function that describes a data class attribute and its initialization, default, and representation behavior.
- match objectA match object represents one regular-expression match and provides information about that match, such as its location.
- encapsulationEncapsulation is the object-oriented design principle of restricting direct access to internal implementation details while exposing an appropriate interface.
- re.searchre.search is a Python re-module function that searches a string for the first match of a regular-expression pattern and returns a match object or None.
- dictionary comprehensionA dictionary comprehension is Python syntax for constructing a dictionary by iterating over an iterable and optionally filtering or transforming items into key-value pairs.
- type functiontype is a Python built-in function that returns the type of an object.
- special methodA special method is a Python method with a language-defined naming convention and protocol role, commonly using double underscores to control built-in object behavior.
- data integrityData integrity is the preservation of data's correctness, validity, and consistency throughout its lifecycle.
- quantifierA quantifier is a regular-expression construct that specifies how many occurrences of a preceding element may or must appear.
- base exception classA base exception class is an application-defined exception superclass from which a package's related custom exceptions inherit.
- atomic typeAn atomic type is a type whose supported accesses and operations are indivisible with respect to concurrent execution and provide defined synchronization semantics.
- regex groupingA capturing group is a delimited subexpression in a regular expression whose matched substring is retained for later access.
- re.matchre.match tests whether a regular-expression pattern matches beginning at the start of a string and returns a match object when successful.
- booleanA boolean value is a truth value representing one of two logical states, true or false, in Python.
- multiple return valuesMultiple return values are values expressed by a function return statement and represented at runtime as one returned object, commonly a tuple.
- don't repeat yourself principleDRY is the software design principle that each piece of knowledge or behavior should have a single authoritative representation.
- interpolationString interpolation is the insertion of variable or expression values into a string template to produce textual output.
- yieldThe yield keyword pauses a generator function, provides a value to its caller, and allows execution to resume later from the pause point.
- iterator methoditer is a Python built-in function that returns an iterator for an iterable object or raises an exception when the object is not iterable.
- stream handlerA stream handler is a logging component that sends log records to a stream such as a console or file-like object.
- enumeration memberAn enumeration member is a named value belonging to an enumeration type and representing one choice in its fixed set.
- strideA stride is the step interval between successive positions or elements accessed, selected, or processed along a dimension or sequence.
- databaseA database is an organized collection of data managed for storage, retrieval, and modification by software.
- variable namingVariable naming is the practice of choosing identifiers that clearly indicate the values or roles they represent.
- lazy evaluationLazy evaluation is an evaluation strategy in which an operation or value is computed only when its result is needed.
- character classA character class is a regular-expression shorthand or bracketed construct that matches characters sharing a specified property or membership condition.
- regular-expression anchorA regular-expression anchor is a zero-width matching construct that constrains a match to a position such as the beginning or end of text.
- groupA group method is a regular-expression match operation that returns the substring captured by specified groups or the complete match when no group number is supplied.
- serializationSerialization is the process of converting native program objects or values into a JSON representation.
- json.dump()dump is a json-module function that serializes a Python object and writes the resulting JSON representation to a file-like object.
- set intersectionSet intersection is the operation that produces the elements common to two sets or set-compatible collections.
- dictionary view objectA dynamic view object is a dictionary-backed object that exposes derived keys, values, or key-value pairs and automatically reflects changes to the dictionary.
- getLoggergetLogger is a function in Python's logging module that returns the named logger associated with a logging hierarchy.
- delimiterA delimiter is a character, sequence, or other marker that separates or marks boundaries between portions of text or structured data.
- collections.abccollections.abc is a Python standard-library module defining abstract base classes for common container and iterable interfaces.
- slice objectA slice object is a Python object that represents the start, stop, and step parameters for selecting elements from a sequence.
- object-oriented programmingObject-oriented programming is a programming paradigm that organizes software around objects containing data and related behavior.
- precisionNumeric precision formatting controls the number of digits displayed for a numeric value.
- cross-platform developmentThe property of software being able to run across multiple operating-system or hardware platforms with little or no platform-specific modification.
- SQLSQL is a standardized language for defining, querying, and modifying data in relational databases.
- leading underscore conventionThe leading underscore convention prefixes an identifier with an underscore to signal intended internal or non-public use without enforcing access restrictions.
- plain textA text file is a persistent file that stores character data in an encoding intended to represent textual content.
- pass statementThe pass statement is a Python statement that performs no operation and can satisfy a syntactic requirement for a code block.
- type errorTypeError is the Python exception raised when an operation or function receives an object of an inappropriate type or an incompatible kind of argument.
- union typeA union type specifies that a value may belong to one of several permitted data types.
- method resolution orderMethod resolution order is the ordered sequence of classes Python searches to find an attribute or method for an instance.
- expressionAn expression is a syntactic form in Python that can be evaluated to produce a value.
- partial applicationA partial function is a callable object created from another callable by pre-filling some of its arguments.
- starred targetA starred expression is Python unpacking syntax prefixed with an asterisk that captures all otherwise unmatched items into a list.
- accessor methodAn accessor method or function provides access to an object's property or state by retrieving its value, assigning a value, or defining behavior for such access.
- KeyErrorKeyError is the Python exception raised when a mapping is accessed with a key that is not present.
- couplingLoose coupling is a software design condition in which components have minimal dependencies on one another's implementation details.
- super keywordThe super construct accesses or invokes inherited methods, constructors, or attributes according to a language’s inheritance rules.
- evaleval is Python's built-in function that evaluates a string or code object as a Python expression and returns its result.
- __getattr____getattr__ is a Python special method invoked to provide an instance attribute value when ordinary attribute lookup cannot find that attribute.
- assertionA software assertion is an executable check of an expected condition or property that signals failure when the check does not hold.
- json.dumps()dumps is a json module function that serializes a Python object to a JSON-formatted string.
- metadataMetadata is information that describes, identifies, or provides context about other data, resources, or artifacts.
- ValueErrorValueError is the Python exception raised when an operation receives an argument of an appropriate type but an inappropriate value.
- raise statementA raise statement is Python syntax that explicitly signals an exception during program execution.
- type signatureA function signature is the interface-level description of a function's name and parameters, and in some languages its return information.
- DictReaderDictReader is a csv-module reader that maps each CSV row's fields to keys taken from the header row.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
