liveBook · Manning

Chapter 3: The quick Python overview

What you will learn in chapter 3 of The Quick Python Book, Fourth Edition

This chapter introduction frames the coming Python overview as a first impression rather than a detailed lesson, with specifics covered in later chapters.

After this chapter you will be able to

Section by section

Introduction

This chapter introduction frames the coming Python overview as a first impression rather than a detailed lesson, with specifics covered in later chapters.

3.1 Python synopsis

This section sketches Python’s data types, objects, control flow, exception handling, and flexible variables.

Key terms: built-in data types, language operators, built-in functions, library functions, methods, classes, class instances, object, if-elif-else, while

3.2 Built-in data types

Introduces the range of Python’s built-in data types, from scalars to more complex structures.

Key terms: built-in data types, scalars, numbers, Booleans, lists, dictionaries

3.2.1 Numbers

This section introduces Python’s four number types and shows basic arithmetic, complex-number attributes, and ways to call numeric functions.

Key terms: integers, floats, complex numbers, Booleans, True, False, arithmetic operators, /, //, exponentiation

3.2.2 Lists

This section introduces what Python lists can hold and how to access and change them with indices, slices, operators, and methods.

Key terms: list, elements, positive indices, negative indices, slice, slice notation, replace, operators, list methods, attribute notation

3.2.3 Tuples

This subsection introduces tuples as immutable, list-like sequences and shows how to create and convert them.

Key terms: tuple, immutable, index, slice, count, in, one-element tuple, comma, elements, list

3.2.4 Strings

This subsection surveys how Python strings are written, used as immutable sequences, processed, and printed.

Key terms: strings, single, double, triple single, triple double, tab (\t), immutable, in, +, *

3.2.5 Dictionaries

Introduces dictionaries as key-value collections and explains their key restrictions, basic operations, and behavior when a key is missing.

Key terms: dictionary, associative array, hash tables, key-value pairs, immutable, KeyError, get, len, del, dictionary methods

3.2.6 Sets, frozensets

Introduces sets as unordered collections for uniqueness and membership, and frozensets as immutable sets.

Key terms: set, unordered collection, membership, uniqueness, in, frozenset, immutable

3.2.7 File objects

This section introduces file objects through a write-and-read example, explains how absolute paths preserve access after a directory change, and names other Python input/output facilities.

Key terms: file object, open, write ("w") mode, read ("r") mode, current working directory, os module, absolute pathname, input, sys, stdin

3.3 Type hints in Python

This section explains why Python offers type hints and distinguishes checks by external tools from errors raised by Python itself.

Key terms: type hints, typed variables, return values, type-checking tools, runtime exception, compile time

3.4 Control flow structures

3.4.1 Boolean values and expressions

This subsection explains which Python values count as true or false and names the operators used to form Boolean expressions.

Key terms: False, True, None, empty values, comparison operators, logical operators, and, not, or

3.4.2 The if-elif-else statement

Explains how an if-elif-else statement selects a block to execute and how indentation defines its blocks.

Key terms: if, elif, else, True, indentation, blocks, statements

3.4.3 Structural pattern matching with match

Introduces Python’s match statement as a pattern-matching feature available from Python 3.10.

Key terms: match statement, pattern matching, switch statements

3.4.4 The while loop

This subsection introduces condition-controlled repetition with while and distinguishes break from continue.

Key terms: while loop, condition, True, break, continue, iteration

3.4.5 The for loop

This section explains how a Python for loop visits items in an iterable and how continue and break affect that loop.

Key terms: for loop, iterable, sequence, foreach loop, continue, break, iteration

3.4.6 Function definition

This subsection summarizes how Python functions are defined, return values, and receive arguments.

Key terms: def statement, return statement, None, positional arguments, keyword arguments, *, **, tuple, dictionary

3.4.7 Exceptions

Introduces how Python catches exceptions, handles errors it defines itself, and uses else and finally clauses.

Key terms: try-except-else-finally, try block, except block, else clause, finally clause, uncaught exception, Exception, EmptyFileError, raise

3.4.8 Context handling using the with keyword

This section introduces `with` and context managers as a streamlined way to ensure cleanup when working with a file, even if an exception occurs.

Key terms: with keyword, context manager, try-except-finally pattern, cleanup action

3.5 Module creation

This section explains how to create and import a module, run it as a script, refresh it after edits, and group modules into packages.

Key terms: module, module search path, sys.path, import statement, attribute syntax, documentation strings, docstrings, comments, script, import

3.6 Object-oriented programming

Introduces Python’s object-oriented syntax through a shapes example, showing how classes are initialized, inherited methods are called, and special methods are used implicitly.

Key terms: class, __init__, instance variables, subclass, base class, method, def, self, move, attribute syntax

3.7 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 2: Getting started Chapter 4: The absolute basics →

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.