course content

Course Content

Introduction to Python

Tuple MethodsTuple Methods

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 n copies of the tuple t
  • t.count(x) - returns the number of times x appears in the tuple t

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 .append() or .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.

Section 4.

Chapter 7