5,337
edits
Line 306: | Line 306: | ||
==Data Structures== | ==Data Structures== | ||
===Tuples=== | |||
Tuples are immutable lists. This means that have fixed size and fixed elements, though elements themselves may be mutable. | |||
In general, they perform marginally faster than lists so you should use tuples over lists when possible, especially as parameters to functions. | |||
<syntaxhighlight lang="python"> | |||
# Tuple with one element | |||
m_tuple = (1,) | |||
# Tuple with multiple elements | |||
vals = (1,2,3, "car") | |||
</syntaxhighlight> | |||
===Lists=== | ===Lists=== | ||
The default data structure in Python is lists.<br> | The default data structure in Python is lists.<br> |