Presentation is loading. Please wait.

Presentation is loading. Please wait.

Intro to Computer Science CS1510 Dr. Sarah Diesburg

Similar presentations


Presentation on theme: "Intro to Computer Science CS1510 Dr. Sarah Diesburg"— Presentation transcript:

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


Download ppt "Intro to Computer Science CS1510 Dr. Sarah Diesburg"

Similar presentations


Ads by Google