Python Tutorial · Revision notes
Python Syntax, Keywords & Operators
Syntax is the set of rules for writing valid Python code. This chapter covers indentation and statements, reserved keywords, literals, all operator groups with precedence, and comments.
Quick revision
- Python uses indentation (4 spaces) to form blocks; headers end with a colon.
- Python is case-sensitive; identifiers cannot start with a digit or be keywords.
- There are about 35 keywords; True, False, None are capitalised; list them with keyword.kwlist.
- Literals: numeric (int, float, complex), string, boolean, None, collections.
- Operators: arithmetic, comparison, assignment, logical, bitwise, identity (is), membership (in).
- / is true division, // is floor division, % remainder, ** power (right-associative).
- Precedence: ** > * / // % > + - > comparisons > not > and > or.
- Comments start with #; docstrings use triple quotes and are stored in __doc__.