Welcome to
CS1315 Intro to Media Computation
“Our greatest weakness lies in giving up.
The most certain way to succeed
is always to try just one more time.”
– Thomas Edison
Day 13
Review - Using range() with the for Loop
•The range function simplifies the process of creating a
sequence
•range returns an iterable object
•Format: (start, stop, step)
•start at index, go until stop index, by step value
•range characteristics:
•One argument: used as ending limit
•Two arguments: starting value and ending limit
•Three arguments: third argument is step value
Spring/Fall 2026
2
Review - enumerate()
• returns an iterable as an enumerate object, adding a counter
as the key to the object.
enumerate(iterable, start)
y = enumerate('hello')
print(y)
# WRONG: displays the memory location of the object
<enumerate object at 0x0000018D98F817B0>
y = enumerate(['apple', '3', 'True'])
print(list(y))
[(0, 'apple'), (1, '3'), (2, 'True')]
y = enumerate(('red', 'green', 'blue'))
print(list(y))
[(0, 'red'), (1, 'green'), (2, 'blue')]
Spring/Fall 2026
3
Review – is operator
• test whether two variables refer to the same object
• Not a test of equality
• mutable objects (list), each is a different object even
with the same elements. is will be False
• immutable objects (str, tuple), variables reference the
same immutable object of elements. is will be True
Spring/Fall 2026
4
Review - List alias vs clone
• Alias: changes to one object affects the other
• Created using the assignment operator
•b=a
• Clone: changes to one object does not affect
the other
• Created using slicing
• b = a[:]
Spring/Fall 2026
5
Review – list input parameter (alias)
• passing a list as an argument passes a reference to the list, not
a clone of the list.
• the called function has the alias
def double_stuff(a_list):
""" Overwrite each element in a_list with double its value. """
for i in range(len(a_list)):
a_list[i] *= 2
things = [2, 5, 9]
double_stuff(things)
print(things)
Spring/Fall 2026
6
Reality Check
Spring/Fall 2026
7
<class tuple>
Tuples are used to store multiple items in a single variable, designated by
parenthesis.
Tuples are one of 4 built-in data types (tuple, dictionary, list, set) in Python used to
store collections of data that are ordered and unchangeable.
Spring/Fall 2026
8
Tuple
• a group of any number of items reference as a single value.
• a comma-separated sequence of values enclosed in parentheses.
• are ordered, meaning the items have a defined order, and that order will not
change (immutable).
• are indexable and iterable
tuple = ()
tuple = (value, value,…)
variable = tuple(iterable)
Spring/Fall 2026
9
Tuple - creation
# with () standard format
year_born = (“Riley Anderson", 2004)
# without () allowed
parents = "Mom", "Dad"
# single value tuple must have ‘ , ’ after the value
oneTup = (5,)
oneTup = (5)
# <class ‘tuple'>
# <class 'int'>
# tuple() constructor function
newTuple = tuple(["apple", 22, "cherry"]
Spring/Fall 2026
10
Tuple - ‘+’ and ‘*’
emotions = ("Joy", "Sadness", "Anger", "Fear")
emotions = emotions + ("Disgust", 2015)
#('Joy', 'Sadness', 'Anger', 'Fear', 'Disgust', 2015)
emotions = emotions + tuple(["Inside Out 2", 2024])
#('Joy', 'Sadness', 'Anger', 'Fear', 'Disgust', 2015, 'Inside Out 2', 2024)
emotions = ("Joy", "Sadness")
emotions = emotions * 2
#('Joy', 'Sadness', 'Joy', 'Sadness')
Spring/Fall 2026
11
Tuple - assignment
Variables on the left are assigned values from a tuple on the right
(variable, variable,…)= tuple
# packing
emotions = ("Joy", 11, "Hockey")
print(emotions) # ('Joy', 11, 'Hockey’)
# unpacking
emotion, age, sport = emotions
print(emotion, age, sport) # Joy 11 Hockey
Spring/Fall 2026
12
Tuple - assignment
Variables on the left are assigned values from a tuple on the right
# swapping
a = 18
b = 'vote'
print(f"{a = },{b = }")
#a = 18, b = 'vote'
(a , b) = (b , a)
print(f"{a = },{b = }")
#a = 'vote’, b = 18
Spring/Fall 2026
13
Tuple – as a return value
• allows functions to return more than one value in a single variable
return (variable, variable,…)
def myFunction(rollList, nameList):
newTup1=(rollList[0], nameList[0])
newTup2=(rollList[1], nameList[1])
return (newTup1,newTup2)
#create tuple
#create tuple
player1, player2 = myFunction([1, 2], ['Mike', 'Ram'])
print(player1, player2)
(1, 'Mike') (2, 'Ram')
Spring/Fall 2026
14
Tuple - .count()
• returns the number of times a specified value occurs in a tuple
tuple.count(value)
thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5)
countOf = thistuple.count(5)
print(f"{countOf = }")
countOf = 2
Spring/Fall 2026
15
Tuple - .index()
• searches for a specified value and returns the first position if found
tuple.index(value)
thistuple = (1, 3, 7, 8, 7, 5, 4, 6, 8, 5)
location = thistuple.index(8)
print(f"{location = }")
location = 3
Spring/Fall 2026
16
Tuple - summary
✓a tuple is a compound data structure
✓similar to a list in that it can store mixed data types
✓similar to a string in that it is immutable
✓tuples can only be concatenated or multiplied
✓tuples are great for swapping values
✓tuples are used so a function can return multiple values as one object
✓tuples only have two methods .count and .index
Spring/Fall 2026
17
Time to program
1. Launch Canvas
o Click Files – Lecture Files – day13_liststuples.py
o download the file to your CS1315 folder
2. Launch VSCode
o Click on File - Open Folder
o Select your CS1315 folder
o Click on the downloaded file for today
Spring/Fall 2026
18
After Class
1. Log into CANVAS
• Read current announcements
• Complete your Homework
• Study for Quiz #3 on Friday
2. Read textbook Chapter 10
3. Review lecture notes and code from today
4. Practice Python: W3schools, Real Python, Codecademy,
Khan Academy
5. hydrate, eat well, get some rest, and laugh!
SPRING/FALL 2026
19