4_Python for loops and Tuple, Set
4_Python for loops and Tuple, Set
Looping Through an Entire List A for loop is used for iterating over a
collection (or sequence) (that is either a list,
Collection a tuple, a dictionary, a set, or a string)
Start
Stop
1
Using range() to Make a List of Numbers
Start = 0
Making Numerical Lists
Start Stop Step
The dir() function: returns all properties and methods of the specified object, without the values.
Making Numerical Lists
List Comprehensions
• First 10 square numbers into a list
Practice
4-3,…, 4-9
Working with Part of a List
Slicing a List
Overwriting a tuple
Practice
4-13
Sets
Defining a Set: A set is a collection which is unordered and
unindexed. In Python sets are written with curly brackets.
Remove Item