Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

What's the difference between arrays and tuples in python?

+2 votes
asked 5 days ago by Eidnoxon (2,430 points)
I have been learning python as my 2nd programming language after javascript (Stopped learning it). When learning python, I haven't really paid attention to small things like the difference between tuples and arrays. Both of them can store some specific value, all I know is the difference is that in arrays we put our values we want to store between []'s, in tuples we store them between ()'s. Just please, tell me the difference.

4 Answers

0 votes
answered 4 days ago by rynecjohnston (140 points)
Tuples are immutable and static, while lists are mutable and dynamic.
0 votes
answered 4 days ago by Sushma (120 points)

Tuples have a slight performance improvement to lists and can be used as indices to dictionaries. Arrays only store values of similar data types and are better at processing many values quickly

0 votes
answered 3 days ago by The Dukk Of Code (140 points)
A tuple is a type of array that is ordered and immutable. In other words, a tuple is like a list (also a type of array) but you can’t change, add, or remove objects from it.
0 votes
answered 3 days ago by Peter Minarik (69,270 points)

This page makes a nice comparison.

Some highlights:

  • in arrays, only same kinds of elements can be stored, in tuples, different types can be stored too.
  • array elements can be changed, tuple elements cannot be changed.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...