Loops Flashcards
1
Q
How do you get the index of an element in a loop?
A
for i in range(5):
i = [0, 1, 2, 3, 4]
2
Q
True or False: You have to define an increment in a loop in Python
A
False - index is incremented implicitly
3
Q
How would you loop through a specific index range in Python?
A
for i in range(2, 6):
i = [2, 3, 4, 5]
4
Q
True or False: The last index in a Python loop is included in the loop
A
False - the last value is not included
5
Q
How would you loop in reverse order in Python?
A
for i in range(6, 2, -1)
i = [6, 5, 4, 3]