Download presentation
Presentation is loading. Please wait.
Published byΣειληνός Βλαχόπουλος Modified over 6 years ago
1
Intro to Computer Science CS1510 Dr. Sarah Diesburg
Lists and Tuples Intro to Computer Science CS1510 Dr. Sarah Diesburg
2
Tuples Tuples are easy: they are simply immutable lists.
They are designated with a comma: Not the parenthesis! myTuple = (1,’a’,3.14,True) newTuple = (,) #Empty tuple anotherTuple = 2,3 #Tuple without parenthesis
3
The Question is, Why? The real question is, why have an immutable list, a tuple, as a separate type? An immutable list gives you a data structure with some integrity, some permanency, if you will. You know you cannot accidentally change one.
4
Lists and Tuples Everything that works with a list works with a tuple except methods that modify the list/tuple. Thus indexing, slicing, len, print all work as expected. However, none of the mutable methods work: append, extend, remove.
5
Anagram Example with Tuples
Let’s make an anagram program and look at how we can use it with lists and tuples
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.