CircuitPython Built-Ins

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 just some of the many featuers you can use

Things that are Built In and Work

Flow Control

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


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 ints and floats whenever you expect.

Tuples, Lists, Arrays, and Dictionaries

You can organize data in ()',  []'s , and {}'s 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.


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

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

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.

Last updated on 2018-03-07 at 12.06.26 PM Published on 2017-10-12 at 10.43.39 PM