← Courses

Python for AI — Beginner Foundations

Data Science

Data Structures · Lesson 36 of 76

Tuples

A tuple is an ordered collection, like a list — but it cannot be changed after you make it. Use a tuple for a fixed group of values that belong together.

Python

Because tuples don't change, they're safe to pass around without worrying something will alter them. Trying to change one is an error:

Python

Run that to see the TypeError — Python protecting the tuple. If you need to change items, use a list instead.

Your turn: make a tuple of your birth (day, month, year) and print the year.

You’re reading for free. Sign in to keep your progress and earn a certificate when you finish.Sign in to keep my progress →