SunFounder Thales Kit for Raspberry Pi Pico, Release 1.0
3.5.11 Lists
Lists are used to store multiple items in a single variable, and are created using square brackets:
B_list
=
[
"Blossom"
,
"Bubbles"
,
"Buttercup"
]
(B_list)
List items are changeable, ordered, and allow duplicate values. The list items are indexed, with the first item having
index [0], the second item having index [1], and so on.
C_list
=
[
"Red"
,
"Blue"
,
"Green"
,
"Blue"
]
(C_list)
# duplicate
(C_list[
0
])
(C_list[
1
])
# ordered
C_list[
2
]
=
"Purple"
# changeable
(C_list)
>>> %Run -c $EDITOR_CONTENT
['Red', 'Blue', 'Green', 'Blue']
Red
Blue
['Red', 'Blue', 'Purple', 'Blue']
A list can contain different data types:
A_list
=
[
"Banana"
,
255
,
False
,
3.14
]
(A_list)
>>> %Run -c $EDITOR_CONTENT
['Banana', 255, False, 3.14]
List Length
To determine how many items are in the list, use the len() function.
A_list
=
[
"Banana"
,
255
,
False
,
3.14
]
(
len
(A_list))
>>> %Run -c $EDITOR_CONTENT
4
Check List items
Print the second item of the list:
A_list
=
[
"Banana"
,
255
,
False
,
3.14
]
(A_list[
1
])
>>> %Run -c $EDITOR_CONTENT
[255]
Print the last one item of the list:
3.5. MicroPython Basic Syntax
133
Summary of Contents for Thales Kit
Page 1: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 Jimmy SunFounder Jun 04 2021 ...
Page 2: ......
Page 4: ...ii ...
Page 6: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 2 CONTENTS ...
Page 140: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 136 Chapter 3 For MicroPython User ...
Page 164: ...SunFounder Thales Kit for Raspberry Pi Pico Release 1 0 160 Chapter 4 For Arduino User ...