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?

+4 votes
asked Mar 18, 2023 by Eidnoxon (5,260 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.

5 Answers

0 votes
answered Mar 19, 2023 by rynecjohnston (140 points)
Tuples are immutable and static, while lists are mutable and dynamic.
0 votes
answered Mar 19, 2023 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 Mar 20, 2023 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 Mar 21, 2023 by Peter Minarik (88,520 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.
0 votes
answered Mar 30, 2023 by 21981A4466 BOORA SRI HARSHA VARDHAN (140 points)
A tuple is immutable and ordered and it allows duplicate values but the array is different unlike the arrays in  other programming languages we have list in python A list is ordered and it can be changed and it allows duplicate values when we want to make any operations on tuple suppose if we want to change the element at a particular index we have to type cast the tuple into a mutable thing

for example lets see this in detail:







But here we are taking about arrays in python it provides a separate library such as numpy to make manipulations on array

There is a variation between numpy Arrays and lists in python



>>><class 'list'>

suppose if you want to work with the numpyarrays the firstly You need to install the library in the python by using the pip command

then you need to import numpy

>>>import numpy



>>>[1 2 3 4]

we get a list without the delimeter comma

this is the main difference between list arrays and tuple in python
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.