// language-transpile
Translate a documented subset of Python to JavaScript and back — fully client-side, deterministic, no external calls.
// output will appear here
// how-it-works
Line + indentation rewriter
The engine walks the source line by line and rewrites each line against a documented subset of syntax patterns. It is not a full parser — it is a deterministic rewriter.
Indentation ↔ braces
Python indentation becomes JS braces on the way in; JS braces become Python indentation on the way out. A small stack tracks open blocks in both directions.
Pattern-level rewriters
Keywords, operators, and builtins are rewritten at the pattern level: print → console.log, len(x) → x.length, and / or / not → && / || / !.
Not a compiler
Unsupported constructs — classes, async/await, lambda, destructuring — are left verbatim and flagged in the annotations list. The tool is honest about its limits.
// supported-subset
This tool deliberately translates a small, documented subset. Anything outside this list is left verbatim and flagged in the annotations panel.
Python → JavaScript
| Python | JavaScript |
|---|---|
| def name(a, b): | function name(a, b) { |
| if cond: | if (cond) { |
| elif cond: | } else if (cond) { |
| else: | } else { |
| while cond: | while (cond) { |
| for i in range(n): | for (let i = 0; i < n; i++) { |
| for i in range(a, b): | for (let i = a; i < b; i++) { |
| for x in xs: | for (const x of xs) { |
| print(x) | console.log(x) |
| True / False / None | true / false / null |
| and / or / not | && / || / ! |
| len(x) | x.length |
| x.append(y) | x.push(y) |
| # comment | // comment |
| x = expr | let x = expr; (or x = expr; if declared) |
JavaScript → Python
| JavaScript | Python |
|---|---|
| function name(a, b) { | def name(a, b): |
| if (cond) { | if cond: |
| } else if (cond) { | elif cond: |
| } else { | else: |
| while (cond) { | while cond: |
| for (let i = 0; i < n; i++) { | for i in range(n): |
| for (const x of xs) { | for x in xs: |
| console.log(x); | print(x) |
| true / false / null | True / False / None |
| && / || / ! | and / or / not |
| === / !== | == / != |
| x.push(y) | x.append(y) |
| x.length | len(x) |
| // comment | # comment |
| let x = y; / const x = y; | x = y |