Module 3 Flashcards
What data type is the following?
(10, 20)
Tuple
What is the result of this comparison?
2 == 2.0
True
What is the difference between these two operators?
“=“
“==“
= is the assignment operator. It assigns a value to a variable
== is the equality operator. It compares two values
What is this operator or and what does it do?
!=
The not equal operator. This checks whether two values or expressions are not equal to each other
It is a binary operator.
Returns a Boolean value
What is this operator?
<=
Less than or equal to
What is this operator? And what does it do?
> =
Greater than or equal to
It is a binary operator
It compares values on either side of it
It has left side binding
As far as priority goes, where do the greater than, less than, greater than or equal to, and less than or equal to operators sit in the spectrum?
They are below binary addition subtraction operators and above the equality and not equal operators
What is a group of if-elif-else statements called?
A cascade
What does the max() function do?
Finds the largest number out of multiple arguments or an iterable
List the comparison operators
== equal
!= not equal
> Greater than
< Less than
>= greater than or equal to
<= less than or equal to
Are comparison operators binary?
Yes
Do uppercase letters have a higher ASCII value than lowercase letters?
No
In fact, lowercase letters have a higher value than their uppercase counterparts
A number corresponding to a character is called a:
Codepoint
can len() return the value of an int or a float?
No
What is the output of this code?
x = 10
if x == 10:
print(x == 10)
if x > 5:
print(x > 5)
if x < 10:
print(x < 10)
else:
print(“else”)
True
True
else
all If statements are evaluated
The final code block is an If/Else statement. Since the If fails, then the Else is triggered
What is the output of the following snippet?
x = 1
y = 1.0
z = “1”
if x == y:
print(“one”)
if y == int(z):
print(“two”)
elif x == y:
print(“three”)
else:
print(“four”)
one
two
Both if statements are evaluated
Since the second if belongs to an if/elif/else block, once the first if is successfully evaluated the elif and the else are skipped
a “while” statement repeats the execution of the code inside it as long as the condition evaluates to _________
True
An instruction or set of instructions executed inside the while loop is called
the loop’s body
True or False?
If the “while” condition is False when it is evaluated the first time then the loop’s body is executed at least once
False
If the “while” condition is false when it is first evaluated, then the loop’s body is never executed
What is another name for an Infinite Loop?
An Endless Loop
What is the “for” loop designed for?
To browse large collections of data
Like the results of a database query
i.e.
new_row = []
for row in results:
order_num = row[1]
new_row.append(order_num)
any variable after the “for” keyword is the __________ variable
control
What does the control variable of a “for” loop do?
it counts the loop’s turns automatically
Is the range() function inclusive
No
It is exclusive.
So, range(100) will give you all values from 0 to 99