Cheat sheet · Foundations
Programming foundations cheat sheet (Python)
FreeA quick-revision companion to the Programming foundations roadmap: language basics, Git, how computers run code, data structures, clean design, testing and shipping projects. Skim a chapter before a project, an exam or a technical conversation, and open the concept you half remember.
Chapters
9 chapters · 77 concepts
1Language basicsThe building blocks every program uses: values and types, decisions, loops, functions, strings and missing values. Get these automatic before anything else.9 concepts
- 1Variables and typesA variable is a name that refers to a value.
- 2Static and dynamic typingStatically typed languages (Java, C++, C#) check types when the code is compiled.
- 3ConditionalsCode that runs only when a condition is true, with
else ifbranches checked in order and an optionalelsefor everything left. - 4LoopsA loop repeats a block of code: a for-each loop visits every item in a collection, a counting
forloop runs over a range of indexes, and awhileloop… - 5FunctionsA named block of code that takes inputs (parameters), does one job and can return a result.
- 6ScopeScope is the part of the code where a name is visible.
- 7Strings and formattingA string is a sequence of text characters.
- 8Null and missing valuesA special value meaning "nothing here":
Nonein Python,nullandundefinedin JavaScript,nullin Java and C#. - 9Reading and validating inputReading text typed by a user or passed to the program, then converting it to the type you need, such as an integer, and rejecting anything that does not fit.
9 in this chapterOpen this chapter2Collections, errors and filesThe core collections you use every day, what happens when you share them, and how to handle errors, files and code split across modules.8 concepts
- 1Lists and dynamic arraysAn ordered collection that grows as you add items and gives fast access by index:
listin Python, arrays in JavaScript,ArrayListin Java,std::vectorin… - 2Dictionaries and mapsA collection of key and value pairs where you look a value up by its key, such as a product name to its stock count.
- 3SetsAn unordered collection of unique values with fast membership checks.
- 4Mutability and copyingA mutable value can change in place; an immutable one cannot.
- 5ExceptionsAn exception is an error object thrown when something goes wrong.
- 6Reading files and cleaning upFiles, network connections and locks must be closed when you are done, even if an error happens halfway.
- 7Modules and importsA module is a file (or group of files) of related code that other files import by name.
- 8Reading errors and debuggingA stack trace lists the chain of function calls that led to an error, with file names and line numbers.
8 in this chapterOpen this chapter- 1Lists and dynamic arraysAn ordered collection that grows as you add items and gives fast access by index:
3Python essentialsThe idioms that make Python code look like Python: comprehensions, generators, type hints, dataclasses and the traps every beginner meets once.7 concepts
- 1ComprehensionsA compact expression that builds a list, dictionary or set by transforming and filtering another iterable, in one line.
- 2Generators and
yieldA function that usesyieldproduces values one at a time, pausing between them, instead of building a whole list in memory. - 3Truthiness and
is NoneIn a condition, empty collections,0,""andNonecount as false and almost everything else as true. - 4Mutable default argumentsDefault values are created once, when the function is defined, not on every call.
- 5Type hintsAnnotations that state the expected types of parameters, return values and variables.
- 6DataclassesA decorator that writes
__init__,__repr__and__eq__for a class from its annotated fields. - 7The main guardThe check
if __name__ == "__main__":is true only when the file is run directly, not when another file imports it.
7 in this chapterOpen this chapter4Command line and GitThe terminal and Git commands every team expects from day one: moving around, committing, branching, working with GitHub and recovering from mistakes.11 concepts
- 1Shell navigationThe shell is a text interface for running programs and working with files.
- 2Repositories and commitsA Git repository stores the full history of a project.
- 3Staging areaThe staging area holds the changes that will go into the next commit.
- 4.gitignoreA file listing patterns of files and folders Git should not track, such as dependencies, build output, logs and local secrets.
- 5BranchesA branch is a movable name that points to a commit.
- 6Merging and rebasingMerging joins another branch into yours, adding a merge commit if both changed.
- 7Merge conflictsA conflict happens when two branches changed the same lines.
- 8Remotes: clone, fetch, pull and pushA remote is a copy of the repository on a server such as GitHub, usually named
origin. - 9Pull requestsA pull request asks to merge one branch into another on GitHub.
- 10Undoing mistakes
restorediscards uncommitted changes to a file,commit --amendfixes the last commit,revertadds a commit that undoes an old one,resetmoves your… - 11Commit messagesA short summary line in the imperative mood (about 50 characters), a blank line, then a body that explains why the change was made.
11 in this chapterOpen this chapter5How computers run your codeEnough of what happens below your code that memory and number bugs stop surprising you: bits, text, the CPU, memory, compilers and the operating system.10 concepts
- 1Bits, bytes and binaryA bit is a 0 or 1.
- 2Text encoding and UnicodeUnicode gives every character a number (a code point).
- 3How the CPU runs a programThe CPU repeatedly fetches an instruction from memory, decodes it and executes it: simple steps such as add, compare, jump and copy.
- 4Compiled and interpreted codeA compiler translates source to machine code before running (C++).
- 5Stack and heapThe stack holds each running function's local variables in frames that vanish when it returns.
- 6Passing arguments to functionsPython, JavaScript and Java always pass a copy of the value, but for objects that value is a reference, so the function can change the object but not rebind…
- 7Garbage collectionThe runtime frees heap objects automatically once nothing can reach them.
- 8Floating point numbersFloats store numbers in binary with limited precision, so most decimal fractions such as 0.1 are approximations.
- 9Integer overflowFixed-size integers have a maximum.
- 10Processes and threadsThe operating system runs each program as a process with its own memory.
10 in this chapterOpen this chapter6Data structures and Big-OThe handful of structures most code is built from, and how to reason about the time and memory a solution costs as the input grows.10 concepts
- 1Big-O notationBig-O describes how the running time or memory of an algorithm grows as the input size n grows, ignoring constants.
- 2Arrays and amortised growthAn array stores items side by side in memory, so reading by index is O(1).
- 3Linked listsA chain of nodes where each node holds a value and a pointer to the next (and, in a doubly linked list, the previous) node.
- 4StacksA last-in, first-out collection: you push onto the top and pop from the top, both O(1).
- 5Queues and dequesA queue is first-in, first-out: add at the back, remove from the front, both O(1).
- 6How hash tables workA hash table turns a key into a number with a hash function, uses it to pick a bucket in an array, and stores the entry there.
- 7Trees and binary search treesA tree is a hierarchy of nodes with one root, where each node has children and no cycles.
- 8GraphsA graph is a set of nodes (vertices) connected by edges, which may have directions or weights.
- 9RecursionA function that calls itself on a smaller version of the problem, with a base case that stops the calls.
- 10Binary searchSearching a sorted array by checking the middle element and discarding the half that cannot contain the target, until it is found or the range is empty.
10 in this chapterOpen this chapter7Object-oriented design and clean codeHow to organise programs so they stay readable as they grow: classes where they help, clear boundaries, good names and the principles reviewers ask about.10 concepts
- 1Classes and objectsA class is a blueprint that groups data (fields) with the behaviour that works on it (methods).
- 2EncapsulationKeeping an object's data private and exposing only the operations that keep it valid.
- 3Inheritance and compositionInheritance builds a class from a parent class and reuses its code ("is a").
- 4Interfaces and polymorphismAn interface is a contract listing methods a type must provide.
- 5Separation of concernsSplitting a program so each part handles one concern: reading input, business logic, storage and output live in separate functions or modules.
- 6DRY, KISS and YAGNIDRY: keep each piece of knowledge in one place.
- 7Naming and small functionsNames that say what a value is or what a function does (
unpaid_invoices,send_reminder), and functions short enough to do one thing at one level of detail. - 8SOLIDFive design principles: a class has one reason to change; extend behaviour without editing working code; subtypes must work wherever the parent does; keep…
- 9Code smells and refactoringA code smell is a sign of a deeper design problem: long functions, duplicated blocks, many parameters, deep nesting.
- 10Comments, docstrings and READMEsComments explain why code does something non-obvious.
10 in this chapterOpen this chapter8Testing your codeUnit tests on the logic that matters, test-driven development, test doubles and the edge cases that break most beginner programs.5 concepts
- 1Unit testsSmall automated tests that call one function or class with known input and assert on the result.
- 2Test-driven developmentWriting a failing test first (red), then the least code that makes it pass (green), then cleaning up (refactor), in short cycles.
- 3Test doublesStand-ins for real dependencies in tests: a stub returns fixed answers, a fake is a simple working version (an in-memory store), and a mock checks how it was…
- 4Edge casesInputs at or beyond the limits of normal use: empty collections, zero, negative numbers, one item, very large values, missing fields and unexpected text.
- 5The test pyramidA guideline for balancing test types: many fast unit tests, fewer integration tests that check parts working together, and a few slow end-to-end tests through…
5 in this chapterOpen this chapter9Build and ship projectsTurning skills into finished, shareable work: scoping, JSON and APIs, dependencies, configuration, a good README and publishing on GitHub.7 concepts
- 1Scoping a small projectCutting an idea down to the smallest version that solves one real problem end to end, then splitting it into a handful of milestones.
- 2Reading and writing JSONJSON is a text format for objects, arrays, strings, numbers, booleans and null.
- 3Calling a public APISending an HTTP request (usually
GETorPOST) to a web service and reading its response, typically a status code plus a JSON body. - 4Virtual environments and pipA virtual environment is a project-local folder with its own Python packages.
- 5Configuration and secretsSettings that change between machines (API keys, URLs, file paths) are read from environment variables or a local config file instead of being written into the…
- 6Writing a READMEThe front page of a repository: what the project does and for whom, a demo, how to install, run and test it, how it works and its known limits.
- 7Publishing on GitHubPushing a project to a public GitHub repository with a README, a licence, a
.gitignoreand a clean history of meaningful commits.
7 in this chapterOpen this chapter- 10Glossary, A to ZEvery concept in the sheet and the smaller terms it uses, in one list.160 terms
About this sheet
First language, Git, CS basics.
Related on Sefism
Picked from the other libraries by shared topics.
Roadmaps
See allBest practices
See all- Python Best PracticesWrite Python that stays maintainable: supported versions, pyproject and lockfiles, Ruff, type hints, errors, logging, concurrency, pytest and security.
- TypeScript Best PracticesModern TypeScript best practices for 2026: strict settings, TypeScript 7, modeling data with unions, safe narrowing, runtime validation, generics and typed linting.
- Secure Coding Best PracticesWrite code that resists attack: untrusted input, validation, parameterized queries, output encoding, safe parsing, uploads, SSRF and errors that fail closed.
Checklists
See all- Pull Request Checklist: Before You Open a PRA pull request checklist to run before you ask for review: scope and size, a clean diff, tests, a clear description, safe releases and a tidy branch, each with a way to verify it.
- Career Switch into Tech ChecklistMove into software from another field step by step: choose a direction, follow a learning plan, build proof of skill, use your previous domain, network, plan your runway and target a first role.
Project structures
See all- Python package and CLI project structureA command line tool published to PyPI, laid out the way the Python Packaging User Guide and uv recommend: a src layout, one pyproject.toml for metadata and every tool, a thin Typer CLI over plain, testable modules, and releases uploaded by GitHub Actions with trusted publishing. The example is mdlinks, a tool that finds broken links in Markdown files. For students who have written Python scripts and want to ship one that strangers can
pip install. - TypeScript npm library project structureA small, typed npm package (a retry helper) built the way modern libraries ship in 2026: TypeScript source in
src, bundled by tsdown intodistwith type declarations and anexportsmap, tested with Vitest, checked with publint and Are the Types Wrong, versioned with Changesets and published from CI with npm provenance. For students who want to publish their first package, and for anyone whose package works locally but breaks for users. - Flutter project structureFor anyone building one Dart app for Android, iOS and the web. The tree starts from what flutter create gives you and grows into a feature-first lib/ folder, where each feature keeps its own data, domain and presentation code, then adds tests at every level, flavors, release signing, crash reporting and, for large teams, a melos workspace of local packages.
Career questions
See all- What should I learn first to become a software engineer in 2026?Learn one language properly, then Git, the command line, how the web works and basic SQL, and build small things with them from week one. AI tools change how you write code, not what you need to understand. Pick a direction only after the foundations feel boring.
- Should I learn Python or JavaScript first?Choose based on what you want to build. JavaScript if you want web development, since it runs in every browser. Python if you are drawn to data, AI, automation or backend scripting. Both are excellent first languages, and the second one is far easier once you know the first well.
- I understand tutorials but cannot build anything myself. Why does coding feel so different when I am alone?Tutorials train recognition, not production. When you follow along, someone else makes every decision. Building alone requires you to break a problem down and make choices, which is a separate skill. Build it with small projects, planning on paper first, and a rule to struggle before you look anything up.
Cheat sheets
See all- Software design and clean code cheat sheetOOP, SOLID, design patterns, refactoring.
- TypeScript cheat sheetTypes, inference, narrowing, generics, type-level tools and strict configuration for real TypeScript codebases.
- Design Patterns cheat sheetAll 23 Gang of Four patterns with intent, when to use and a TypeScript sketch, plus SOLID, related principles and a problem to pattern map.
Work with me
Stuck on something specific?
Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.
- 1:1 Mentorship
- Fresh Graduate Mentorship
- Career Guidance
Brand deals, promos and partnerships: tauseeffayyaz@gmail.com