Site Tools


Hotfix release available: 2026-07-14c "Mort". upgrade now! [57.3] (what's this?)
Hotfix release available: 2026-07-14b "Mort". upgrade now! [57.2] (what's this?)
Hotfix release available: 2026-07-14a "Mort". upgrade now! [57.1] (what's this?)
New release available: 2026-07-14 "Mort". upgrade now! [57] (what's this?)
Hotfix release available: 2025-05-14b "Librarian". upgrade now! [56.2] (what's this?)
Hotfix release available: 2025-05-14a "Librarian". upgrade now! [56.1] (what's this?)
New release available: 2025-05-14 "Librarian". upgrade now! [56] (what's this?)
Hotfix release available: 2024-02-06b "Kaos". upgrade now! [55.2] (what's this?)
Hotfix release available: 2024-02-06a "Kaos". upgrade now! [55.1] (what's this?)
New release available: 2024-02-06 "Kaos". upgrade now! [55] (what's this?)
Hotfix release available: 2023-04-04b "Jack Jackrum". upgrade now! [54.2] (what's this?)
Hotfix release available: 2023-04-04a "Jack Jackrum". upgrade now! [54.1] (what's this?)
New release available: 2023-04-04 "Jack Jackrum". upgrade now! [54] (what's this?)
Hotfix release available: 2022-07-31b "Igor". upgrade now! [53.1] (what's this?)
Hotfix release available: 2022-07-31a "Igor". upgrade now! [53] (what's this?)
New release available: 2022-07-31 "Igor". upgrade now! [52.2] (what's this?)
New release candidate 2 available: rc2022-06-26 "Igor". upgrade now! [52.1] (what's this?)
New release candidate available: 2022-06-26 "Igor". upgrade now! [52] (what's this?)
Hotfix release available: 2020-07-29a "Hogfather". upgrade now! [51.4] (what's this?)
old revision restored (2026/09/13 22:52)
notes:python_cheat_sheet

Python Cheat Sheet

Overview

Python is a dynamic object-oriented programming language with extensive standard libraries. These notes summarize the Python 3.0 tutorial.

The Interpreter

  • python/python3.0 is the command-line interpreter with readline where available.
  • python -c command runs a single command.
  • sys.argv is a list of strings with the script if any in sys.argv[0]
  • »> prompts for a line . … prompts for a continuation of a previous line
  • PYTHONSTARTUP can point to a file of startup commands
  • Expressions are evaluated and printed.
  • The last printed expression is assigned to _ .

Basics

  • Comments start with # .
  • Variables can be assigned (using = ) without being defined but must be assigned before being used.
  • a,b = c,d does a multiple assignment.
  • Imaginary numbers can be created using complex(a,b) or a+bJ. .real and .imag will extract real and imaginary parts.
  • print(“a”,“b”,end=“”) prints a b with no newline at the end.

Lists

  • list=[1 ,'a' , “b”] is a list of three items.
  • list[4] is 4th element. list[2:4] is second and third elements. list[:2] is first 2 elements. list[2:] is third element to last one. list[:] is the whole list.
  • Negative indexes count from last element.
  • List slices can be modified. list[3:3] can be used to insert elements at position 3. list.append() appends to the list.
  • len(list) returns length of the list.
  • Lists can be nested.

Strings

  • Strings can be enclosed with double or single-quotes.
  • \ in a string by itself goes to the next line but does not insert a newline (\n does).
  • A raw string - r“” does no escaping.
  • + concatenates strings, * repeats them .
  • A string can be treated as a list of letters.
  • But strings can't be modified using slices or indexes.
  • String methods include strip, format, capitalize etc.
  • format-string % (tuple) allows use of printf formatting strings. Also string.format() .

Control Flow

notes/python_cheat_sheet.txt · Last modified: 2026/09/14 01:55 by 216.73.217.14