Control Flow Flashcards
This is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated.
Control Flow.
Define iterate (verb).
To perfrom or utter repeatedly.
Com. Sci. Defintion of Iteration.
The repetition of a function or process in a computer program. We can use loops to execute a block of code for every iteration.
What is the purpose of the enumerate function?
A lot of times when dealing with iterators, we also get a need to keep a count of iterations. Python eases the programmers’ task by providing a built-in function enumerate() for this task.
Enumerate() method adds a counter to an iterable and returns it in a form of enumerate object. This enumerate object can then be used directly in for loops or be converted into a list of tuples using list() method.
Say you have a list of tuples, what technique would you use to unpack the elements of the tuples?
Tuple unpacking.
Consider mylist = [(1,2),(3,4),(5,6)], use tuple unpacking to print out the elements of the tuple.
for a,b in mylist:
print(a)
print(b)
This statement allows the for loop to run with no error from python. Without it, python will yell error. This is very useful for functions.
The pass statement.
This statement allows us to go back to the closest enclosing loop.
The continue statement.
This statement breaks the loop and very useful for while loops.
The break statement.
What is another way of saying x = x + 1 in python?
x += 1
This operator is a generator. It generates information instead of saving it.
The range operator.
How would you put a range of numbers into a list?
x = list(range(start,stop,step size))
This is a very common operator in python, it is used to add a counter to a iterable results in a tuple. Useful for strings.
The enumerate function.
Kinda opposite to the enumerate operator, this operator attaches elements of differents lists together.
The zip operator.
A quick way of checking if an item is in a list we would use what keyword?
-in
ex.
>> ‘x’ in [1,2,3]
<< False