How to use the Python Cheat Sheet
- 1. Search or browseType a word like the function or task you need, or pick a section.
- 2. CopyEach snippet has its own Copy button, so you can paste it straight into your editor.
- 3. DownloadSave the whole Python cheat sheet as plain text or Markdown for offline revision.
What's in it
The sheet covers Python 3 essentials for students, interview prep and day-to-day scripting. The 49 snippets are organised into 12 sections: Basics, Strings, Lists, Dicts, Sets & tuples, Control flow, Functions, Errors, Files, Classes, Modules, Tools.
Every snippet that shows a result (marked with →) was run in Python 3, and the output matches what's shown.
Example
Search "reverse" and you get "Uncodemy"[::-1] → 'ymedocnU': a slice with step −1 walks the string backwards. Search "count" and you find both "banana".count("a") → 3 and Counter("banana").most_common(1) → [('a', 3)], which shows two ways to count, one for a single item and one for every item.
Tips for using it
- Use the Section menu to revise one area at a time before an exam or interview.
- Download the Markdown version to keep it in your notes app or GitHub repository.
- Type the snippets into a Python shell rather than just reading them; it sticks better.
A quick look, one snippet per section
- Basics:
print(f"{name} is {age}")(f-string: put variables inside text) - Strings:
"Uncodemy"[1:4](slice: start inclusive, stop exclusive) - Lists:
nums = [3, 1, 2]; nums.append(4)(add to the end) - Dicts:
d = {"a": 1}; d.get("b", 0)(read a key with a default) - Sets & tuples:
set([1, 2, 2, 3])(remove duplicates) - Control flow:
for i in range(1, 10, 2): ...(loop 1, 3, 5, 7, 9) - Functions:
def area(r, pi=3.14): return pi * r * r(default argument) - Errors:
try:(handle an error and always clean up) - Files:
with open("data.txt", encoding="utf-8") as f:(read a file safely (closes automatically))
Search the box above for the rest of the Python snippets, or download the full sheet.
Frequently asked questions
Which Python version?
Python 3.10 and later. match statements need 3.10.
Is pandas included?
No. See the separate pandas cheat sheet.
Is the Python cheat sheet free?
Yes. You can search, read and copy every snippet in the Python cheat sheet without signing up. The first time you download it, we ask once for your name and WhatsApp number; after that downloads and every other Uncodemy tool open straight away.