liveBook · Manning

Python

As explained in The Quick Python Book, Fourth Edition

Python is a high-level general-purpose programming language with an interpreted execution model and dynamic features.

Python is a high-level, general-purpose language suited to quick prototypes and larger programs. It runs on many platforms and is used for web applications, scientific computing, data work, machine learning, and automation. Its concise syntax and extensive libraries often make development faster, though it is not the best choice for every task. section 1.1 section 1.2.1

Python uses indentation—not braces—to mark the body of a loop, conditional, or function. The visible layout is therefore part of the program’s structure. Variables need no declaration and refer to objects; the objects have types, but a variable can later refer to an object of another type. section 4.1 section 1.3.2

A small loop

Start with `n = 9` and `r = 1`. In `while n > 0:`, indent `r = r * n` and `n = n - 1` to repeat both statements. Move either statement back to the left margin and it is no longer in the loop. For a shorter assignment, `r *= n` has the same effect as `r = r * n`. section 4.1

Built-in types include numbers, strings, lists, tuples, dictionaries, sets, and file objects. Functions, classes, modules, exceptions, and control-flow constructs let these pieces grow into programs. A module is a Python file that can be loaded with `import`; the standard library supplies modules for tasks such as operating-system access, databases, and web programming. Third-party packages extend that range. section 3.1 section 1.2.4 section 1.2.5

Count a file’s contents

A short file-analysis program reads a file, splits its contents into lines, then uses a `for` loop to count words and characters. It reports the three totals with `print`. This combines file access, string and list operations, a loop, and formatted output in one everyday task. section 8.12

Dynamic typing is flexible but does not catch an unintended type assignment before execution. Optional type hints document intended variable, parameter, and return types; a checker such as `mypy` can flag inconsistencies, but Python does not enforce the hints at runtime. Exceptions handle runtime errors, and `try` and `except` allow selected errors to be handled explicitly. section 4.4 section 14.5

Python code is compiled to internal bytecode and then run by an interpreter. It can be slower than C, although C or C++ modules can handle CPU-intensive portions. The standard implementation also has a global interpreter lock that limits its use of multiple processor cores; commercial mobile-app development can be awkward. Weigh those constraints against development speed and library availability. section 1.3.1 section 1.3.4 section 1.3.3

How The Quick Python Book, Fourth Edition covers it

How deep it goes
Develops syntax, types, program structure, libraries, and error handling through examples; gives only a brief account of interpreter internals.
Examples
Demonstrates an indented factorial loop, a file-based word counter, and type mismatches reported by mypy.
What it assumes
Assumes general programming experience but teaches Python syntax without requiring prior Python knowledge.
What you can do after
Build it from scratch: write and run small Python programs using built-in types, control flow, files, and modules.
How it connects
Connects Python to dynamic typing, type hints, indentation, modules, exceptions, and the standard library.

Also explained in

Compare how 26 books explain Python →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Quick Python Book, Fourth Edition. The section links point to the parts of the book it draws on.