The unofficial CircuitPython Reference

tuple()

description

Python provides builtin functions that explicitly convert between data types. This is commonly known as casting. It is often necessary to cast values when they are used as arguments in a function call. It is generally necessary to cast values whenever a function or other process cannot implicitly convert a given variable to the appropriate datatype. For example when storing RGB color data in a list it is necessary to cast the list to a tuple before using the values in a neopixel object.

tuple(variable) is used to cast lists and other sequential types to the tuple type.

syntax

convert list to tuple

my_list = [255, 0, 255]

my_tuple = tuple(my_list)

methods

parameters

returns

example code

serial output:

code.py output:

[255, 0, 255]

(255, 0, 255)

see also: