Conditional Logic Flashcards
What is range?
a special type of object that takes in two parameters, start(inclusive) and stop(exclusive), and returns an object containing the elements from start to finish
it also takes a 3rd optional parameter, step
example: range(1, 10)
1, 2, 3, 4, 5, 6, 7, 8, 9
What is enumerate?
enumerate takes in an iterable and will give you an index counter and the item at that index
for i, char in enumerate(my_list):
is vs ==
== – checks for equality of value as it evaluates both terms to check if they are both truthy or falsy
is – is stricter as it actually checks if the location in memory where the value is stored, is the same
what is short circuiting?
it is the concept that when the interpreter evaluates if and logic or if or logic, it will ‘cut short the circuit’ as able
example: a program uses if and logic. The first conditional evaluates to False. The interpreter will know to end the operation because there’s no point in continuing the operation since the condition has been violated
what is the ternary operator?
it is a shortcut for writing one line conditional statements
example:
condition_if_true if condition else condition_if_false
break vs continue vs pass
break: this keyword exits the loop
continue: this keyword exits the current iteration of the loop
pass: is a good way to set a placeholder while you’re unsure what you want to do