Introduction to Python
Let's take a look at the main tuple methods.
len(t)- returns the length of the tuple
t(i.e., number of elements)
t * n- returns
ncopies of the tuple
t.count(x)- returns the number of times
xappears in the tuple
In the last chapter, we pointed out that tuples are immutable. Is there a way to update a tuple with new values? Unlike lists, methods like
.extend() are not available for tuples. However, three chapters ago, you used another method called concatenation. This one is available for tuples:
tuple1 + tuple2- concatenation (both terms must be tuples);
For example, let's update the tuple from the previous example with new information.
Note that the new data must be stored in a tuple in order to perform concatenation.