Chapter 3. The Python Language
This chapter is a guide to the Python language. To learn Python from scratch, we suggest you start with the appropriate links from the online docs and the resources mentioned in “Python documentation for nonprogrammers”. If you already know at least one other programming language well, and just want to learn specifics about Python, this chapter is for you. However, we’re not trying to teach Python: we cover a lot of ground at a pretty fast pace. We focus on the rules, and only secondarily point out best practices and style; as your Python style guide, use PEP 8 (optionally augmented by extra guidelines such as those of “The Hitchhiker’s Guide to Python”, CKAN, and Google).
Lexical Structure
The lexical structure of a programming language is the set of basic rules that govern how you write programs in that language. It is the lowest-level syntax of the language, specifying such things as what variable names look like and how to denote comments. Each Python source file, like any other text file, is a sequence of characters. You can also usefully consider it a sequence of lines, tokens, or statements. These different lexical views complement each other. Python is very particular about program layout, especially lines and indentation: pay attention to this information if you are coming to Python from another language.
Lines and Indentation
A Python program is a sequence of logical lines, each made up of one or more physical lines. Each physical line ...
Get Python in a Nutshell, 4th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.