Control Flow Flashcards
What is indentation?
Indentation is Python’s way of symbolizing which code is within a conditional statement or loop.
How many space are there in indentation?
4 spaces or a press of Tab.
What is an iterable?
An iterable is an object that can return one of its elements at a time.
How do you create a list with the range function?
print(list(range(start, stop, step))) Step is optional and default is 1.
Which code can you use to repeat an action a certain amount of times?
for iteration_variable in range(amount repetitions):
[code]
What is the difference between a for and while loop?
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.
What does the break keyword do?
It breaks the code when a condition is met or completed. (Can be used for both while and for loops)
What does the continue keyword do?
It skips one iteration to check if the condition remains true.
What does the zip function do?
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 can you unzip a list?
You just add an * while still using the zip function.
What does the enumerate function do?
It gets the index and puts it along with a value.