Jump to content

Python: Difference between revisions

238 bytes added ,  13 July 2020
Line 310: Line 310:
Tuples are immutable lists. This means that have fixed size and fixed elements, though elements themselves may be mutable.
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.
In general, they perform marginally faster than lists so you should use tuples over lists when possible, especially as parameters to functions.
Typically people use tuples as structs, i.e. objects with structure such as coordinates. See [https://stackoverflow.com/questions/626759/whats-the-difference-between-lists-and-tuples StackOverflow: Difference between lists and tuples].
<syntaxhighlight lang="python">
<syntaxhighlight lang="python">
# Tuple with one element
# Tuple with one element