The basics of loops in python Flashcards
Which of these Python data types can NOT be iterated through using for loops?
tuple
list
string
int
int
Which TWO of the following statements about for loops in Python are TRUE?
They may have an associated else block
They can iterate over the elements in tuples, lists, and dictionaries
ven the following code, what is the type of x which is printed out in each iteration?
my_list = [[‘tiger’, ‘lion’, ‘leopard’], [‘camel’, ‘llama’, ‘alpaca’], [‘zebra’, ‘donkey’, ‘wildebeest’]]
for x in my_list:
print(x)
A list of strings
Given a variable my_dict which is a dictionary, consider you use it in a for loop in this manner:
for x in my_dict:
print (x)
What are the contents printed out?
The keys in the dictionary
What is the correct value of x given the assignment shown?
x = list(range(-17, -7, 2))
[-17, -15, -13, -11, -9]
Which of the following function calls will generate the list below?
[10, 7, 4, 1, -2]
list(range(10, -3, -3)