Python
Online Python Editor
The editor above is CodeMirror set up for Python: Ruff checks each .py file as you type, Tab indents by four spaces, and Ctrl+Enter (⌘+Enter on a Mac) runs the open file on Python 3.12. Below is what it does, with the keys as the app has them.
Try it aboveHow Python runs here
- Versions
- Python 3.11, 3.12 (default), 3.13, 3.14, 3.15
- Run
python3 -u main.py- Limits per run
- 256 MB memory, 15 s of CPU time on 2 cores, 2 MB of output
- Time
- Up to 10 minutes a run (30 on a paid plan); waits 2 minutes for input (5 on a paid plan)
- Sandbox
- Each run gets its own Linux sandbox with no network access. Text files your program writes next to your code open as new tabs.
- Good to know
- NumPy, pandas, Matplotlib and openpyxl installed.
Problems before you press Run
Ruff, the Python linter, runs in your browser and checks the file again as you edit. Problems get a wavy underline; hover one for the message and rule code, or open the Problems tab beside Console for the full list. This short file has five:
import os def average(scores): total = 0 return sum(scores) / len(score) if average([3, 4]) == None: print(f"no scores")
- Line 1: `os` imported but unused (F401)
- Line 4: Local variable `total` is assigned to but never used (F841)
- Line 5: Undefined name `score` (F821), a typo that would otherwise surface as a NameError only when that line runs
- Line 7: Comparison to `None` should be `cond is None` (E711)
- Line 8: f-string without any placeholders (F541)
Ruff also marks syntax and indentation mistakes while you type, such as Expected an indented block after `for` statement. It doesn’t check types. Turn it off under Settings → Files and running → Lint with Ruff.
Keys for editing Python
Ctrl on Windows and Linux is ⌘ on a Mac:
- Tab and Shift+Tab indent or outdent the selected lines one level, which in Python moves them into or out of a block.
- Ctrl+/ comments or uncomments the selected lines with #.
- Alt+↑ and Alt+↓ move the line or selection, say a statement out of a loop; Shift+Alt+↑ and Shift+Alt+↓ copy it.
- Ctrl+Shift+K deletes the line.
- Ctrl+D selects the next occurrence of the word at the cursor: press it until every use of a variable is selected, then type its new name once. Alt+drag puts a cursor on each line of a column.
- Ctrl+F finds and replaces, Ctrl+G jumps to the next match, and Ctrl+Alt+G goes to the line number a traceback gave you.
- Ctrl+Shift+[ folds the def or class at the cursor and Ctrl+Shift+] unfolds it (⌘+Alt+[ on a Mac).
- Ctrl+Enter runs, Ctrl+, opens settings, and F2 on a tab renames the file.
Settings → Keyboard shortcuts lists them all, and the search box at the top of settings finds a shortcut by name.
Settings that matter for Python
- Indentation: four spaces, as PEP 8 recommends. Switch Indent with to Tabs in a file that already uses spaces and Python stops with TabError: inconsistent use of tabs and spaces in indentation.
- Show whitespace draws spaces as dots and tabs as arrows, so a stray tab inside an indented block is easy to spot.
- Key bindings: Standard, Vim (Esc for normal mode, i to insert) or Emacs (Ctrl-a, Ctrl-e, Ctrl-k).
- Font: Fira Mono by default, or JetBrains Mono, Source Code Pro, IBM Plex Mono, Roboto Mono, Ubuntu Mono, Inconsolata, Menlo or Consolas, at 10 to 28 px. Ligatures, off by default, join -> and != into single glyphs in fonts that have them.
- Theme: Light and Dark use the colors of VS Code’s Light+ and Dark+; System follows your computer.
- Console: Focus the console on Run is on, so you can answer input() without clicking, and Clear before each run can be turned off to compare output between runs.
Completions
Suggestions while typing offers names and keywords from the file, so a long variable name takes two or three letters and Enter. AI code completions show as gray text that Tab accepts and Esc dismisses, and Ctrl+K asks for a change to the selected code, shown as a diff before it applies.
Files, breakpoints and limits
- The + after the tabs adds untitled.py, ready to rename. Uploads must be text files, up to 3 MB for the whole playground.
- Download all files as python-playground.zip, or Share a link to them (up to 128 KB) that opens a copy anyone can run and change.
- Click in the margin left of a line number to set a breakpoint, a red dot; Debug next to Run then pauses there.
- Autosave keeps the files in this browser a moment after you stop typing. With it off, Ctrl+S saves and leaving with unsaved changes asks first.
Questions
Does the editor find errors before I run the code?
Yes, for Python. Ruff checks the file as you type and lists undefined names, unused imports, syntax and indentation errors under Problems. It doesn’t check types.
How do I turn on Vim mode?
Settings → Editor → Key bindings → Vim. Esc enters normal mode and i goes back to inserting.
Can I indent with 2 spaces?
Yes: Settings → Editor → Tab size, from 1 to 8. Keep one style per file, since Python rejects a block that mixes tabs and spaces.
Can I put the console below the code?
Yes: Settings → Appearance → Layout → Below. Auto, the default, puts the console beside the code on wide screens and below it on narrow ones.
Does it work on a phone or tablet?
Yes. On a narrow screen the console moves below the code and settings open as a sheet from the bottom.