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]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

True or False: You have to define an increment in a loop in Python

A

False - index is incremented implicitly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How would you loop in reverse order in Python?

A

for i in range(6, 2, -1)

i = [6, 5, 4, 3]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly