-1

In Python, there are 3 Array like datatypes (unless I'm forgetting one).

Those being Tuples ((1,2,6,3)), Lists ([1,2,6,3]), and Sets ({1,2,6,3}).

They each have different methods defined to them, but when is it correct to use one over the other? There are questions and answers already about these but none of them seem to say when to use one over the other.

They can each be converted to one another so it's possible to just use one over the other and convert when necessary. Though that probably isn't a preferred method.

So, I ask, under what situation would you choose one type over the other?

Spedwards
  • 4,167
  • 16
  • 49
  • 106

1 Answers1

1

To summarize the documentation, a list is a mutable sequence that preserves its order and can have non-unique elements; a set is a mutable collection that does not preserve its order and cannot have non-unique elements, and a tuple is an immutable sequence that preserves its order and can have non-unique elements. Bonus: a dict is a mutable collection that does not preserve its order and cannot have non-unique keys. See the linked documentation for more details.

TigerhawkT3
  • 48,464
  • 6
  • 60
  • 97