Tuples and lists
Both are arrays, but tuples are immutable. This means that once you define a tuple, you cannot add elements, pop, append, remove an element, etc. You need to create a new tuple out of the old one every time you make a change.
- Tuples (1,2,3,4,5,6) are great for static definition. They are hashable, lean and unequivocal.
- Lists [1,2,3,4,5,6] are great for computation. They are mutable and queueable.
Both are addressed with integers in brackets.
Whether it is a list or a tuple, addressing one element is the same.
create a tuple with y = (“a”,”b”,”c”) and do this;
y = ("a","b","c") print (y) for i in y: print (i)
For lists and tuples, know this too;
for i in range(0,len(y)): print (i,y,y[i])
Now redefine y as a list and try it again. Same results?