4.5
Which is an invalid variable name?
python
for
For
false
for
(false is a valid variable name... False is not)
Evaluate both:
False and False
False or (True or False)
False and False == False
False or (True or False) == True
What are the two prevailing types of loops in Python, and what are they each used for?
for loops: when the number of iterations is known
while loops: when the end condition is known
What data type is returned by the input() function?
A string
9 // 2
4
You can always use the comma to chain together variables in a print statement, like print("Your score is", score)
When can you also use a plus (+) to do the same?
When all variables involved are strings
What are the symbols for the following bitwise operations:
and
or
xor
not
left shift
and: &
or: |
xor: ^
not: ~
left shift: <<
How do lists differ from dictionaries?
Lists are indexed with integers, dictionaries can be indexed with strings or other data types.
What does the "break" keyword do in a loop?
Exits the loop even if it hasn't completed
2 ** 2 ** 3
256 (2 to the (2 to the 3))
A function is defined with the signature below:
def my_fun(var1, var2)
How should it be rewritten so that var2 has a default value of 6?
def my_fun(var1, var2=6)
6 in binary is 0000 0110. What is ~6 in binary?
1111 1001
What will print?
my_list = ['a', 'b', 'c', 'd', 'e']
print(my_list[::2])
['a', 'c', 'e']
What will be printed by the following line of code?
print("Z" * 3)
"ZZZ"
When dividing a float by an int, what data type will the result be?
float
What is printed by the following code snippet?
n = 3
n **= 2
print(n)
9
Same thing as:
n = 3
n = n ** 2
print(n)
Complete the xor table:
1 xor 1 ==
1 xor 0 ==
0 xor 1 ==
0 xor 0 ==
1 xor 1 == 0 (False)
1 xor 0 == 1 (True)
0 xor 1 == 1 (True)
0 xor 0 == 0 (False)
What's the difference between the .append() and .insert() methods for lists?
.append() adds an element to the end of the list, .insert() can add elements anywhere in a list
What does a "try/except" block allow a programmer to do?
Anticipate errors and prevent the program from crashing when they're encountered
3 % 17
What is the syntax for creating a tuple called "bear_creek" which holds the values "K-8" and "High School"?
bear_creek = ("K-8", "High School")
What effect does left shifting (<<) have on a number's value?
Multiplies the number by 2 for every bit shifted
In Python, a non-ordered, non-repetitive collection of items is known as what?
A set
Where did Python get its name?
Monty Python's Flying Circus