QUESTIONS & ANSWERS
string, tuple, range, integer, float, Boolean - ANSWER-List the data types in python that are
IMMUTABLE
list, dictionary, set - ANSWER-List the data types in python that are MUTABLE
for, while - ANSWER-Use a for/while loop when you know exactly how many times a loop needs
to run, and a for/while loop when you can't predict how often it repeats
docstring - ANSWER-optional comments are called this
'''Hello'''
parentheses, index (slicing), exponent, multiplication/division/modulus, add and subtract,
comparisons, Boolean (not, and, then or) - ANSWER-Order of operations in python
string, list, tuple, set, dictionary (NOT int, float, bool) - ANSWER-data types in python that are
iterables
0, 1 - ANSWER-For splicing x[a:b:c]:
if a is missing, the value is ___
if c is missing, the value is __
if b is missing, the value is the length of the string.
brackets, parentheses, squiggly braces, - ANSWER-What are each of the following data
structures inclosed in:
lists
tuples
dictionaries and sets
sets are unordered and unindexed, dictionaries are ordered and mutable - ANSWER-What is the
difference between sets and dictionaries?
5, 6, 7, 8, 9 - ANSWER-range(5,10) returns what?
yes - ANSWER-Can lists have heterogenous elements?
,ex: ['dog', 78]
functions - ANSWER-range() and main() are considered these in python
element - ANSWER-in the list ['hello', 78], hello and 78 are called this.
{1, 2, 3, 'c', 'b', 'a'} - ANSWER-what is the output of this union:
a = {1,2,3}
b = {'a', 'b', 'c'}
a|b
{2, 3} - ANSWER-what is the output of this intersection:
a = {1,2,3}
b = {2,3,4}
a&b
print('Hello World') - ANSWER-What is a correct syntax to output "Hello World" in Python?
my-var - ANSWER-Which one is NOT a legal variable name?
my-var
Myvar
my_var
_myvar
print(type(x)) - ANSWER-What is the correct syntax to output the type of a variable or object in
Python?
def myFunction(): - ANSWER-What is the correct way to create a function in Python?
T - ANSWER-T/F
In Python, 'Hello', is the same as "Hello"
x = "Hello"[0] - ANSWER-What is a correct syntax to return the first character in a string?
x = "Hello"[0]
,x = sub("Hello", 0, 1)
x = "Hello".sub(0, 1)
strip() - ANSWER-Which method can be used to remove any whitespace from both the
beginning and the end of a string?
upper() - ANSWER-Which method can be used to return a string in upper case letters?
replace() - ANSWER-Which method can be used to replace parts of a string?
== - ANSWER-Which operator can be used to compare two values?
dictionary - ANSWER-What is this called?
{"name": "apple", "color": "green"}
list - ANSWER-Which collection is ordered, changeable, and allows duplicate members?
set
list
dictionary
tuple
set - ANSWER-Which collection does not allow duplicate members?
set
list
tuple
break - ANSWER-Which statement is used to stop a loop?
['b','e'] - ANSWER-What is the output of the following program?
a = list('abcdefg')
print(a[1::3])
T - ANSWER-T/F
The first character of a variable in Python can be a letter or an underscore.
, T - ANSWER-T/F
When A is a set, A >= A
F - ANSWER-T/F
When a is a set, a < a
F - ANSWER-T/F
In Python, a variable must be declared before it is assigned a value.
T - ANSWER-T/F
In Python, a variable may be assigned a value of one type, and then later assigned a value of a
different type.
route66, Age, home_address - ANSWER-Which of the following are valid Python variable names:
route66
4square
ver1.3
Age
home_address
return
Concatenates string1 and string2 - ANSWER-What does the expression string1 + string2 do?
Repeats string1 string2 times (string2 must be in numeric format).
Concatenates string1 and string2.
It's a syntax error.
Adds string1 to string2 (both must be in numeric format).
T - ANSWER-T/F
Python syntax is case-sensitive.
x y z = 1 2 3 - ANSWER-Which of the following is an invalid statement?