Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a current, dependable Python cheat sheet, start with the official Python 3.14.7 documentation and use a condensed sheet as a quick syntax reminder—not as a substitute for explanations or the language reference. This task-focused guide covers the everyday essentials and points to the right official docs when a short example is not enough. Version note: Python.org’s documentation landing page identifies Python 3.14.7 and was last updated September 28, 2026.

How to use a Python cheat sheet

A cheat sheet is most useful when you already have a question: How do I loop over a list? What does a dictionary literal look like? How do I catch an exception? Scan the example, adapt it, and follow its documentation link if the answer depends on context. It is a map back to fuller explanations, not a complete course or exhaustive catalogue of Python’s standard library.

The official docs separate those jobs. The tutorial introduces syntax and features; the built-in, library, and language references provide precise detail. The documentation landing page says, “Start here: a tour of Python’s syntax and features.” Find the current sections at docs.python.org/3.

Start the interpreter or run a script

Open the interactive interpreter

After installing Python and making its command available in your terminal, run:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
python

On some systems the command is python3 instead. The prompt lets you try expressions one at a time:

>>> 2 + 3
5

Exit with exit(), or use the keyboard shortcut appropriate to your terminal. Interactive work is handy for small experiments; save code in a file when you want to rerun it or build a program.

Run a saved script

Save this as hello.py, then run it from the directory containing the file:

print("Hello, Python!")
python hello.py

If that command is not found, check that Python is installed and on your PATH, or try python3 hello.py. The exact setup steps depend on your operating system and installation method; use the official documentation’s setup and usage material linked from the documentation home.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Core syntax, comments, and names

Python uses indentation to mark blocks. Keep the indentation consistent—four spaces is the conventional style—and put a colon after the statement that begins a block:

temperature = 18
if temperature < 20:
    print("Bring a jacket")

A # begins a comment that runs to the end of that line. Names are case-sensitive: score and Score are different names. Assignment uses =; comparison uses ==. For example, score = 10 stores a value, while score == 10 tests equality.

Use descriptive names such as item_count. A name cannot begin with a digit, and Python keywords such as if, for, and class cannot be used as variable names. The language reference has the exact rules for identifiers and statements.

Common types, values, and conversions

These built-in types cover many beginner tasks:

Type Example Typical use
int 42 Whole numbers
float 3.14 Numbers with a fractional part
str "hello" Text
bool True Truth values
NoneType None Absence of a value
list ["a", "b"] Ordered, changeable collection
tuple (10, 20) Ordered collection, often used for fixed groups
dict {"name": "Ari"} Key-value mappings
set {"red", "blue"} Collection of distinct values

Convert values explicitly when needed: int("12"), float("2.5"), and str(12). Conversions can fail—for example, int("twelve") raises ValueError. A list can be converted to a tuple with tuple(my_list); a tuple can be converted to a list with list(my_tuple). For exact behavior and the full set of built-ins, consult the built-in functions and types sections in the official reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Strings and collections

Strings

Strings are written with single or double quotes. An f-string inserts an expression into text:

name = "Mina"
count = 3
message = f"{name} has {count} messages"
print(message)

Useful operations include text.lower(), text.strip(), and text.split(","). Strings are immutable: methods return new strings rather than changing the original. Use len(text) to get the number of characters.

Lists and dictionaries

Lists preserve order and can be changed:

colors = ["blue", "green"]
colors.append("red")
first_color = colors[0]
colors[1] = "purple"

Indexes start at zero; colors[-1] accesses the last item. A slice such as colors[0:2] selects from the start index up to, but not including, the end index.

Dictionaries map keys to values:

person = {"name": "Mina", "age": 28}
print(person["name"])
person["city"] = "Leeds"

Use person.get("email") when a missing key should return None instead of raising KeyError. To loop through key-value pairs, write for key, value in person.items():.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Conditions and loops

Choose a branch with if

score = 76
if score >= 90:
    grade = "A"
elif score >= 70:
    grade = "B"
else:
    grade = "Keep practicing"

Comparison operators include ==, !=, <, >, <=, and >=. Combine conditions with and, or, and not. A conditional expression can choose between two values: label = "adult" if age >= 18 else "minor".

Repeat work with for or while

for color in ["blue", "green", "red"]:
    print(color)

for number in range(3):
    print(number)  # 0, 1, 2

A for loop visits items in an iterable. range(3) produces values starting at zero and stopping before three. Use while when repetition depends on a condition:

attempts = 0
while attempts < 3:
    attempts += 1

Make sure a while loop can eventually stop. break exits a loop; continue skips to its next iteration. The tutorial’s control-flow section explains these statements and their subtleties.

Functions and small reusable pieces

Define a function with def. Parameters receive values; return sends a result back to the caller:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
def add_tax(price, rate=0.2):
    return price * (1 + rate)

total = add_tax(10)

Here, rate has a default value, so the call can omit it. A function that reaches the end without a return statement returns None. Use a docstring as the first statement in a function when a short description will help someone use it:

def square(number):
    """Return the square of number."""
    return number * number

For more detail on parameters, return values, and scope, continue to the functions section of the official tutorial.

Classes and objects

Classes define a kind of object. The __init__ method initializes a newly created instance; self refers to that instance:

class Dog:
    def __init__(self, name):
        self.name = name

    def speak(self):
        return f"{self.name} says woof"

pet = Dog("Pip")
print(pet.speak())

You do not need a class for every piece of data or behavior. A few variables and functions are often clearer for small programs. When objects, shared behavior, or a model of a domain make the code easier to organize, read the tutorial’s classes section before adding inheritance or other design complexity.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Exceptions and error handling

Exceptions report errors or other exceptional conditions. Catch only the errors your program can handle meaningfully:

try:
    quantity = int("12")
except ValueError:
    print("Enter a whole number")
else:
    print(f"Quantity: {quantity}")

The except block runs if the conversion raises ValueError; else runs when the protected code succeeds. Avoid a bare except: unless you have a specific reason to catch every exception: it can hide programming errors. When diagnosing a failure, read the final line of the traceback for the exception type and message, then use the preceding lines to locate where it occurred.

Read and write files

Use with so a file is closed when the block ends, even if an error occurs:

with open("notes.txt", "r", encoding="utf-8") as file:
    contents = file.read()

with open("notes.txt", "w", encoding="utf-8") as file:
    file.write("A new noten")

Mode "r" reads; "w" creates or replaces a file; "a" appends. Choose an explicit encoding for text files. A relative path such as notes.txt is interpreted relative to the program’s current working directory, which may differ from the directory you expect if you launched the script elsewhere. The official tutorial and library reference cover file objects, paths, and more advanced I/O.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
excovip Python Commands Shortcuts Mouse Pad -80x30x0.2 cm Extended Large Cheat Sheet Mousepad PC Office Spreadsheet Keyboard Mouse Mat Non-Slip Stitched Edge 0306
  • 【Large Mouse Pad】Our extra-large mouse pad 31.4×11.8×0.07 inch(800×300×2 mm) is perfect for use as a desk mat, keyboard and mouse pad, or keyboard mat, offering you unparalleled comfort and support during long gaming sessions or work days.
  • 【Ultra Smooth Surface】 Mouse Pad Designed With Superfine Fiber Braided Material, Smooth Surface Will Provide Smooth Mouse Control And Pinpoint Accuracy. Optimized For Fast Movement While Maintaining Excellent Speed And Control During Your Work Or Game.
  • 【Highly durable design】-The small office&gaming mouse pad is designed with high stretch silk precision locking edges to avoid loose threads on the cloth. Ensure Prolonged Use Without Deformation And Degumming.
  • 【 Non-slip Rubber Base】-Dense shading and anti-slip natural rubber base can firmly grip the desktop. Premium soft material for your comfort and mouse-control.
  • 【Enhanced Productivity】 Boost your coding efficiency with this handy python keyboard and mouse mat. No more getting stuck on endless online searches or flipping through textbooks, just glance down for the reference you need.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose a cheat sheet or a fuller reference

Different formats solve different problems. Choose by currency, scope, and whether you need a compact scan or a complete explanation:

Resource Best for Format and authority
Python 3.14.7 documentation Learning concepts and checking exact language or library behavior Official, searchable documentation with tutorial and reference sections
Python.org: Our Documentation Finding learning resources, books, and downloadable documentation Official portal; includes downloadable formats, including typeset versions for printing
Real Python Python Cheat Sheet A condensed overview of common beginner topics Third-party web sheet with a printable version; not an official language definition

Real Python’s sheet covers areas such as setup, syntax, types, strings, control flow, functions, classes, errors, and I/O. Python.org also offers downloadable documentation formats, including typeset versions. For a book-length explanation and exercises, Python.org lists books as a learning-resource category; no particular title or edition is endorsed here.

Check the version and avoid stale references

Look for the Python version and update date on any sheet you find. Python changes over time, and library APIs can change independently of the core syntax. The official landing page identifies Python 3.14.7 and links to “What’s New” and deprecations alongside its references. For a feature that might be version-sensitive, confirm it against the docs for the version you actually run.

Search results can also surface historical documents: Chris Hoffmann’s Python.org-hosted A Python Quick Reference explicitly covers Python 1.3 and is dated 1995. It is useful as a historical artifact, not as a current Python 3 cheat sheet.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshoot common beginner snags

  • “python” or “python3” is not recognized: the interpreter may not be installed, or its executable may not be on PATH. Check the installation and command for your operating system, then try the other common command name.
  • IndentationError or SyntaxError: check the indicated line and the one immediately before it. Confirm that block statements end with a colon and their bodies use consistent indentation.
  • NameError: check spelling, capitalization, and whether the name has been assigned before use. Python treats differently capitalized names as distinct.
  • TypeError during arithmetic or string work: inspect the types of the values involved. Convert deliberately where appropriate instead of assuming text such as "12" is already a number.
  • KeyError or IndexError: verify that the dictionary key exists or that the collection has an item at the requested index. Use dict.get() when a missing dictionary key should be handled as a normal case.
  • File not found: check the working directory and the file path. A relative path is resolved from the process’s current directory, not necessarily the script’s location.
  • The sheet’s example behaves differently: confirm its stated Python version and whether it assumes packages, operating-system setup, or data not shown in the snippet; then check the matching official reference.

Or skip the browser setup

If your Python work also needs a screenshot of a web page, ScreenshotNeo can return an image or PDF from one GET request. Its API can remove cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are not billed. It also provides an MCP server for AI agents to take screenshots. The Free plan includes 1,000 screenshots per month with no card, and paid plans start at $5 for 3,000. See the API documentation for options.

import requests

r = requests.get(
    "https://api.screenshotneo.com/v1/shot",
    params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
    timeout=90,
)
open("shot.webp", "wb").write(r.content)

Sign up for ScreenshotNeo to get 1,000 free screenshots a month with no card.

Frequently Asked Questions

Is a Python cheat sheet enough to learn programming?

No. Use it to look up familiar syntax, and work through the official tutorial and examples to learn how concepts fit together.

Can I print Python documentation for offline use?

Yes. Python.org provides downloadable documentation formats, including typeset versions. Real Python also offers a printable cheat sheet.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How can I tell if an old Python reference is still current?

Check its stated version and date, then confirm version-sensitive details against the official documentation for the interpreter you use.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.