We’ll mainly use for loops in this course. Here’s the python syntax for a for-loop:
for i in range(a, b):
The range function produces a list of numbers between the starting number a to the ending number b. By cycling through all the numbers in this list, we run a loop these many times.
Run the next cell, which contains a for-loop to print every number between 1 and 9. In the next cell, write a for-loop to print the employee IDs of the employees mentioned in exampleDf.
There are two easy ways to create a set. The first one is just a direct initialization:
set1 = {"item1", "item2", "item3"}
The second way involves using the set constructor to create a set:
set2 = set(("item1", "item2", "item3"))
Just like with Dictionaries, duplicates are not allowed. Sets don’t have a particular order and the set is unchangeable.
To get the length of a set:
len(set)
A tuple is another way of storing many values in a single variable. Like with Sets, there are two ways to create a new tuple.
tupleOne = ("itemOne", "itemTwo", "itemThree", "itemFour")