Control Flow Flashcards

1
Q

What is indentation?

A

Indentation is Python’s way of symbolizing which code is within a conditional statement or loop.

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

How many space are there in indentation?

A

4 spaces or a press of Tab.

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

What is an iterable?

A

An iterable is an object that can return one of its elements at a time.

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

How do you create a list with the range function?

A

print(list(range(start, stop, step))) Step is optional and default is 1.

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

Which code can you use to repeat an action a certain amount of times?

A

for iteration_variable in range(amount repetitions):

[code]

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

What is the difference between a for and while loop?

A

A for loop repeats an action for a specified amount of time while a while loop does not but repeats till a condition is met.

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

What does the break keyword do?

A

It breaks the code when a condition is met or completed. (Can be used for both while and for loops)

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

What does the continue keyword do?

A

It skips one iteration to check if the condition remains true.

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

What does the zip function do?

A

Zip returns an iterator that combines multiple iterables into one sequence of tuples, each tuple contains the elements in that position from all the iterables.

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

How can you unzip a list?

A

You just add an * while still using the zip function.

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

What does the enumerate function do?

A

It gets the index and puts it along with a value.

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