The unofficial CircuitPython Reference

list [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 list type stores values with a comma separated list contained in brackets: [a, b, c]. Lists are ordered and changeable and their members are accessible by an index number beginning with 0. They may store duplicate members of any primitive data class or most any object.

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 list

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

recall member of a list

my_var = my_list[2]

change a list member

my_list[0] = 'X'

methods

parameters

returns

example code

serial output:

code.py output:

['A', 'B', 'C']

C

['X', 'B', 'C']

see also: