Python Tuples

Buildandteach: Henry Palma
1 min readFeb 17, 2022

--

Features of a Tuple

A tuple is a collection of objects. It contains the following features:

  • It is ordered
  • It is NOT changeable
  • It allows duplicate members
  • Smaller and faster than a list

1) Create a Tuple

Use parenthesis to create a tuple.

2) Access items in a Tuple

Items in a tuple are accessed by index. You can also use slice notation.

3) Get the count of items in an Tuple

To get the count of items in a Tuple use the len() method

4) Check if an item exists in a Tuple

To check if an item exists in a Tuple use the in keyword

5) Loop through items in a Tuple

Use a for loop to loop though items in a Tuple.

6) Add items to a Tuple

Tuples are not changeable. To add an item to a Tuple you must create a new Tuple.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response