Tuples are usually used when sizes / lengths are fixed (possibly by different types) and are listed if there is an arbitrary number of values of the same type.
What is the reason for using tuple instead of list here?
Samples for tuples:
- in a fixed space (e.g. 2d:
(x, y) ) - representation of
dict keys / value pairs (for example, ("John Smith", 38) ) - things where the number of components of a tuple is known before evaluating an expression
- ...
Samples for lists:
- split line (
"foo|bar|buz" splits into | s: ["foo", "bar", "buz"] ) - command line arguments (
["-f", "/etc/fstab") - things in which the number of list items is (usually) unknown before evaluating the expression
- ...
source share