Syntax
MicroPython implements Python 3. You write indentation, functions, classes, exceptions, generators, closures and async/await the same way. The gaps are in the library and in a few implementation limits, not in the look of the language.
What you can rely on
- Integers (arbitrary precision on most builds), floats (when the port enables them), complex on fuller builds.
str,bytes,bytearray,list,tuple,dict,set,frozenset.- List/dict/set comprehensions, unpacking,
*args/**kwargs, decorators, context managers. - Classes with single and multiple inheritance,
@classmethod,@staticmethodand@property. try/except/finally/else,raise,assert.async def,await,async for,async with— paired withasyncio.- f-strings, on builds at the extra-features level and above, which covers most boards. Template strings (PEP 750,
t"…") from 1.28, on builds that switch them on.
Usual differences
| Topic | What happens |
|---|---|
| Standard library | A subset. json, re, struct, time, os, sys are there; pathlib and desktop-only modules are not. |
| Floating point | Optional, and left out of the smallest builds. Most microcontroller builds use single precision (32-bit) floats; the unix, Windows and WebAssembly builds use double precision. |
| Tracebacks | Show the file and line number but not the line of source. Builds below the extra-features level leave out line numbers. |
| Multiple inheritance | Supported, but methods are looked up depth first rather than in CPython’s order, and super() calls only one of the parents. |
eval / exec | Present on most builds; can be compiled out. Code run this way sees global names but not the caller’s local variables. |
| Overriding builtins | Assigning to a name in the builtins module works on builds at the extra-features level and above. |
| Filesystem | open() talks to the on-board flash (or an SD card), not your laptop disk, unless you are on the unix port. |
The maintained list is CPython differences in the official docs.
Identifiers you will see only here
const() from micropython declares a constant the compiler can substitute wherever the name is used. @micropython.native and @micropython.viper emit machine code for a function. mem_info() and alloc_emergency_exception_buf() are runtime knobs. These are not CPython.