Python/An Informal Introduction to Python
[i]Learn· An Informal Introduction to Python

An Informal Introduction to Python

In the following examples, input and output are distinguished by the presence or absence of prompts (>>> and …): to repeat the example, you must type everything after the prompt, when the prompt appears; lines that do not begin with a prompt are output from the interpreter. Note that a secondary prompt on a line by itself in an example means you must type a blank line; this is used to end a multi-line command.

Many of the examples in this manual, even those entered at the interactive prompt, include comments. Comments in Python start with the hash character, #, and extend to the end of the physical line. A comment may appear at the start of a line or following whitespace or code, but not within a string literal. A hash character within a string literal is just a hash character. Since comments are to clarify code and are not interpreted by Python, they may be omitted when typing in examples.

Some examples:

# this is the first comment
spam = 1  # and this is the second comment
          # ... and now a third!
text = "# This is not a comment because it's inside quotes."
Source: An Informal Introduction to Python by Python Software Foundation, licensed under PSF-2.0. Retrieved 2026-11-18. Changes: Extracted the introduction of chapter 3 from The Python Tutorial (Python 3.14), https://docs.python.org/3.14/tutorial/introduction.html; removed section numbers, permalinks and site navigation; code blocks kept as shown; runnable examples: prompts and output lines removed; dropped the paragraph about the documentation site's Copy button.