Conditional Logic Flashcards

1
Q

What is range?

A

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

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

What is enumerate?

A

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):

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

is vs ==

A

== – 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

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

what is short circuiting?

A

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

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

what is the ternary operator?

A

it is a shortcut for writing one line conditional statements

example:

condition_if_true if condition else condition_if_false

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

break vs continue vs pass

A

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

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