The unofficial CircuitPython Reference

tuple (a, b, c)

description

Python has 4 classes for storing collections of data: list, tuple, set, dictionary. Each has different properties in terms of changeability and ordering.

The tuple type stores values with a comma separated list contained in parentheses: (a, b, c). Tuples are ordered and unchangeable and their members are accessible by an index number beginning with 0. They may store duplicate members of any primitive data class.

When declaring a variable in Python it must begin with a letter and the name may only contain letters, numbers, and underscores. For the sake of readability it is conventional to use all lower case letters and numbers for variable names with underscores to separate words. It is best to avoid I and O for single letter variable names as they can look like 1 and 0. Python does not have a constant keyword and there is therefore no enforced constant but again for readability it is conventional to name CONSTANTS with all caps and underscores between words.

syntax

declare a tuple

my_tuple = ('A', 'B', 'C')

recall tuple member

my_var = my_tuple[1]

change a tuple (must redeclare)

my_tuple = ('X', 'Y', 'Z')

methods

parameters

returns

example code

serial output:

code.py output:

('A', 'B', 'C')

B

('X', 'Y', 'Z')

see also: