Skip to content
derpx06.dev
WritingExplainersNotesAbout
works on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisationworks on my machineit's always DNSship itLGTMTODO: sleepoff by oneread the docsgit push --force-with-lease404: sleep not foundhave you tried turning it off and on againrubber duck says: explain itpremature optimisation

Learning in public.

A student's notebook on system design, distributed systems and databases. Shared as I learn.

ReadWritingExplainersNotesAbout
ElsewhereGitHubLinkedInHugging FaceLeetCode
Say hellomanaskhairnar1511@gmail.com
derpx06
NORMALmain© 2026 Derpx06Pune, Indiatop ↑
Learn/Python Overview/Part 3 · 3. Data Structures
Lesson 6 of 17

Tuples

Tuples are lists' immutable cousins.

Derpx061 Jan · 1 min read
Python Overview
ListsTuplesDictionariesSets
Contents
Multiple Return ValuesSwapping
0% read · 1 min leftBack to top ↑
Course outline & contents0%
Python Overview
ListsTuplesDictionariesSets
Contents
Multiple Return ValuesSwapping

Tuples are lists’ immutable cousins. Pretty much anything you can do to a list that doesn’t involve modifying it, you can do to a tuple. You specify a tuple by using parentheses (or nothing) instead of square brackets:

tuples.py
my_list = [1, 2]
my_tuple = (1, 2)
other_tuple = 3, 4
my_list[1] = 3      # my_list is now [1, 3]

try:
  my_tuple[1] = 3
except TypeError:
  print "cannot modify a tuple"

Multiple Return Values

Tuples are a convenient way to return multiple values from functions:

multiple_returns.py
def sum_and_product(x, y):
  return (x + y),(x * y)

sp = sum_and_product(2, 3)            # equals (5, 6)
s, p = sum_and_product(5, 10)         # s is 15, p is 50

Swapping

Tuples (and lists) can also be used for multiple assignment:

swapping.py
x, y = 1, 2
x, y = y, x     # Pythonic way to swap variables; now x is 2, y is 1
Track your progressSign in and your progress follows you across devices.
Sign in to track progress Next lesson
← Previous lessonListsNext lesson →Dictionaries