3 Key Takeaways Flashcards

1
Q

returns True if operands’ values are equal, and False otherwise

A

==

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

returns True if operands’ values are not equal, and False otherwise

A

!=

x != y # True
x != z # False

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

True if the left operand’s value is greater than the right operand’s value, and False otherwise

A

>

x > y # False
y > z # True

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

True if the left operand’s value is less than the right operand’s value, and False otherwise

A

<

x < y # True
y < z # False

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

True if the left operand’s value is greater than or equal to the right operand’s value, and False otherwise

A

x >= y # False
x >= z # True
y >= z # True

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

True if the left operand’s value is less than or equal to the right operand’s value, and False otherwise

A

x <= y # True
x <= z # True
y <= z # False

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

the while loop executes a statement or a set of statements as long as a specified boolean condition is true, e.g.:

A

Example 1
while True:
print(“Stuck in an infinite loop.”)

Example 2
counter = 5
while counter > 2:
print(counter)
counter -= 1

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

the for loop executes a set of statements many times; it’s used to iterate over a sequence (e.g., a list, a dictionary, a tuple, or a set - you will learn about them soon) or other objects that are iterable (e.g., strings). You can use the for loop to iterate over a sequence of numbers using the built-in range function. Look at the examples below:

A

Example 1
word = “Python”
for letter in word:
print(letter, end=”*”)

Example 2
for i in range(1, 10):
if i % 2 == 0:
print(i)

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

You can use the break and continue statements to change the flow of a loop:

A

You use break to exit a loop, e.g.:

text = “OpenEDG Python Institute”
for letter in text:
if letter == “P”:
break
print(letter, end=””)

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

You use continue to skip the current iteration, and continue with the next iteration, e.g.:

A

text = “pyxpyxpyx”
for letter in text:
if letter == “x”:
continue
print(letter, end=””)

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

The while and for loops can also have an else clause in Python. The else clause executes after the loop finishes its execution as long as it has not been terminated by break, e.g.:

A

n = 0

while n != 3:
print(n)
n += 1
else:
print(n, “else”)

print()

for i in range(0, 3):
print(i)
else:
print(i, “else”)

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