What you'll learn: how Python maps onto the Java and Node you know: the syntax differences that trip people, why type hints do not stop a wrong call at runtime, what a virtual environment is, and how a pinned requirements file gives every machine the same packages.
At a glance
Figure 1. What runs your Python code
How to read this: the interpreter sees only your files and the active environment's packages; the type checker is a separate tool outside the path of execution.
- Blocks use indentation, not braces, and no compile step catches a typo.
- Type hints document intent; the interpreter does not enforce them.
- A virtual environment is a per-project folder of packages, like
node_modules. python -m pip install -r requirements.txtrebuilds the same environment anywhere, if every line is pinned.- The capstone pins every package with
==.
Scenario
Composite scenario, not a real company. Lumen Industrial Supply, the fictional distributor, runs its platform on Spring Boot and one Node gateway. A pilot adds document parsing and evaluation scripts, and the vendor's model SDK is easiest to use from Python. The engineer must clone the capstone, run its tests on a locked-down laptop with two Python versions already installed, and add one dependency without breaking a colleague's machine. All names and numbers are illustrative.
What you will be able to do
- Translate common Java and Node constructs into Python and read a Python file without guessing.
- Explain what a type hint does at runtime and predict the result of a wrongly typed call.
- Create a virtual environment and say which interpreter and packages a command uses.
- Install from a pinned requirements file, add a package, and write the new pin.
Prerequisites
What an FDE actually does and Your baseline. You need Java or Node experience and Python 3.12 or newer on your path. For the system the capstone implements, see the AI Architect overview; this page covers only the language and tooling.
Core ideas
The syntax map
| Idea | Java | Node (TypeScript) | Python |
|---|---|---|---|
| Block | { ... } |
{ ... } |
A colon, then an indented block (4 spaces) |
| Null | null |
null, undefined |
None |
| Boolean literals | true, false |
true, false |
True, False |
| Equality and identity | .equals(), == |
=== |
== compares values, is compares identity |
| List and map | List, Map |
Array, Map, object |
list, dict (literals [], {}) |
| Loop over a collection | for (X x : xs) |
for (const x of xs) |
for x in xs: |
| Build a new list | stream().map().toList() |
xs.map(...) |
[f(x) for x in xs if ok(x)] |
| Optional value | Optional<T>, nullable |
T | undefined |
T | None |
| Resource cleanup | try-with-resources | try / finally |
with open(...) as f: |
| Annotation or wrapper | @Annotation |
A higher-order function that wraps another | @decorator, an ordinary function applied to the one below it |
| Entry point | public static void main |
the script file | code at module level, optionally if __name__ == "__main__": |
Three rows deserve a sentence. The Python tutorial says to use "4-space indentation, and no tabs". The reference describes with as wrapping "the execution of a block with methods defined by a context manager". A decorator receives the function below it and whatever it returns takes the function's name; that is how @app.get("/health") registers a route in the next lessons.
Type hints are documentation the interpreter ignores
Predict first. Look at this function. What does the call double("ab") return, and does Python raise an error?
Verified: capstone/fde-product-discovery-copilot/lessons/M1-L1/m1_l1_python_tour.py
def double(x: int) -> int:
return x * 2
Answer
It returns "abab" and raises nothing. A string times an integer repeats the string, and x: int is never checked. The typing documentation says so: "The Python runtime does not enforce function and variable type annotations. They can be used by third party tools such as type checkers, IDEs, linters, etc."
In Java, double("ab") would not compile. In TypeScript the annotations are erased, as in Python. A static checker such as mypy reads the hints and reports mismatches without running the program.
You will see the union syntax most: str | None means a string or nothing, and Optional[X] is equivalent to X | None. Libraries can read hints at runtime, which is what Pydantic and FastAPI do in the next two lessons. Enforcement comes from them, not from the language.
Virtual environments and pinned requirements
| Need | Java (Maven) | Node | Python |
|---|---|---|---|
| Project dependency list | pom.xml |
package.json |
requirements.txt, or a dependencies list in pyproject.toml |
| Where packages live | Managed by the build tool | node_modules/ in the project |
.venv/ in the project |
| Exact-version record | Your build file, if you pin | package-lock.json |
pip freeze output saved to requirements.txt |
| Install everything | Build tool resolves | npm install |
python -m pip install -r requirements.txt |
A virtual environment is, in the Python documentation's words, a "lightweight" environment "with their own independent set of Python packages installed in their site directories". Without one, pip install changes the interpreter every project shares.
Figure 2. Environment and dependency flow
How to read this: every path returns to the tests, because a changed requirements file is trustworthy only once the suite passes on it.