liveBook · Manning

Chapter 4: The absolute basics

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

This chapter introduction previews the Python basics covered in the chapter.

After this chapter you will be able to

What it builds on

Section by section

Introduction

This chapter introduction previews the Python basics covered in the chapter.

4.1 Indentation and block structuring

This section explains how Python uses indentation to define code blocks, why that makes structure easier to read, and where unexpected indentation can cause errors.

Key terms: indentation, block structure, body of the while loop, braces, visual structure, real structure, Python coding styles, Jupyter notebook cell, Python shell’s >>> prompt, error message

4.2 Differentiating comments

This section distinguishes Python comments from # characters inside strings.

Key terms: comment, interpreter, string

4.3 Variables and assignments

This section explains how Python creates and names variables, how names refer to objects, and what happens when a name is reassigned or deleted.

Key terms: assignment, variable names, case sensitive, variables, labels, objects, namespace, immutable values, integer object, references

4.4 Optional type hints in Python

This section explains why Python offers optional type hints and shows how a type checker can flag mismatches that Python itself will still run.

Key terms: type hints, variables, parameters, return values, type-checking tools, mypy, int, float, annotation

4.4.1 Why use type hints?

This subsection explains how type hints clarify expected types and help catch type-related errors while code is being written.

Key terms: type hints, type information, runtime, editors, IDEs

4.4.2 Why not use type hints?

This section explains when the effort and readability costs of type hints may outweigh their benefits.

Key terms: type hints, human readability, completeness of typing, working code, maintenance, refactoring

4.4.3 Progressive typing

This subsection explains that optional type hints can be introduced gradually where they are most useful.

Key terms: type hints, progressively, type information

4.5 Expressions

This section introduces Python expressions, showing how division and arithmetic precedence affect results and noting that expressions can use nonnumeric values.

Key terms: division, floating-point number, integer division, //, arithmetic precedence, parentheses, expressions, strings, Boolean values

4.6 Strings

This section explains how Python string literals use quotes, backslash escapes, and triple quotes.

Key terms: strings, single quotes, double quotes, backslash, escape characters, \n, \t, \\, \", triple-quoted strings

4.7 Numbers

Introduces Python’s numeric types and the behaviors of arithmetic, division, and explicit numeric conversions.

Key terms: integers, floats, complex numbers, Booleans, division (/), // division symbol, float, integer, explicit conversions, truncate

4.7.1 Built-in numeric functions

4.7.2 Advanced numeric functions

This section identifies the standard math module as the source of advanced numeric functions and constants and says they must be made available before use.

Key terms: math, standard module, trig functions, hyperbolic trig functions

4.7.3 Numeric computation

This section explains why intensive numeric computation often calls for NumPy rather than the core Python installation.

Key terms: core Python installation, NumPy, array operations, multidimensional matrices, fast Fourier transform

4.7.4 Complex numbers

This section explains Python’s notation for complex numbers, why their arithmetic results remain complex objects, and how to access their components.

Key terms: complex numbers, j, complex-number object, real, imag, floating-point numbers

4.7.5 Advanced complex-number functions

This section explains why complex-number calculations use cmath rather than math and why explicit module names help keep their functions distinct.

Key terms: math module, cmath module, complex numbers, from <module> import *, name conflicts, override

4.8 The None value

This section explains what None represents, where it appears, and why it is easy to recognize.

Key terms: None, empty value, placeholder, instance, references

4.9 Getting input from the user

This section explains how to prompt a user for input and convert the resulting string when a number is needed.

Key terms: input(), prompt string, string, int(), float()

4.10 Built-in operators

This section notes that Python has familiar arithmetic operators as well as less common operators, without explaining how they work.

Key terms: built-in operators, bit shifting, bitwise logical functions

4.11 Basic Python style

This section distinguishes Python’s few mandatory style rules from the recommended PEP 8 conventions and explains why following those conventions helps readers understand code.

Key terms: indentation, PEP 8, Pythonic style

4.12 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 3: The quick Python overview Chapter 5: Lists, tuples, and sets →

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.