CircuitPython comes 'with the kitchen sink' - a lot of the things you know and love about classic Python 3 (sometimes called CPython) already work. There are a few things that don't but we'll try to keep this list updated as we add more capabilities!

This is not an exhaustive list! It's simply some of the many features you can use.

Thing That Are Built In and Work

Flow Control

All the usual if, elif, else, for, while work just as expected.

Math

import math will give you a range of handy mathematical functions.

>>> dir(math)
['__name__', 'e', 'pi', 'sqrt', 'pow', 'exp', 'log', 'cos', 'sin', 'tan', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'copysign', 'fabs', 'floor', 'fmod', 'frexp', 'ldexp', 'modf', 'isfinite', 'isinf', 'isnan', 'trunc', 'radians', 'degrees']

CircuitPython supports 30-bit wide floating point values so you can use int and float whenever you expect.

Tuples, Lists, Arrays, and Dictionaries

You can organize data in ()[], and {} including strings, objects, floats, etc.

Classes, Objects and Functions

We use objects and functions extensively in our libraries so check out one of our many examples like this MCP9808 library for class examples.

Lambdas

Yep! You can create function-functions with lambda just the way you like em:

>>> g = lambda x: x**2
>>> g(8)
64

Random Numbers

To obtain random numbers:

import random

random.random() will give a floating point number from 0 to 1.0.

random.randint(min, max) will give you an integer number between min and max.

This guide was first published on Aug 02, 2019. It was last updated on Mar 18, 2024.

This page (CircuitPython Built-Ins) was last updated on Mar 08, 2024.

Text editor powered by tinymce.