Font size
WorksheetsPython quiz
Total questions: 10
Worksheet time: 8mins
Which one is NOT a legal variable name?
my_var
Myvar
_myvar
my-var
What is the correct syntax to output the type of a variable or object in Python?
print(typeof(x))
print(type(x))
print(typeof x)
print(typeOf(x))
Which method can be used to remove any whitespace from both the beginning and the end of a string?
ptrim()
len()
strip()
trim()
A while loop in Python is used for what type of iteration?
indefinite
discriminant
definite
indeterminate
Which of these collections defines a LIST?
["apple", "banana", "cherry"]
{"apple", "banana", "cherry"}
("apple", "banana", "cherry")
{"name": "apple", "color": "green"}
What is the output of the following code snippet:
a = ['foo', 'bar', 'baz', 'qux', 'corge']
while a:
if len(a) < 3:
break
print(a.pop())
print('Done.')
corge
qux
baz
corge
qux
baz
Done.
The snippet doesn’t generate any output.
corge
qux
baz
bar
foo
Done.
Will the print() statement on line 5 be executed in this case:
a = ['foo','bar','baz','qux','corge']
while a:
print(a.pop())
else:
print('Done.')
No
Yes
After execution of the following code, what is the value of s?
s = ""
n = 5
while n > 0:
n -= 1
if (n % 2) == 0:
continue
a = ['foo', 'bar', 'baz']
while a:
s += str(n) + a.pop(0)
if len(a) < 2:
break
(a)
What is the output of the following code snippet:
d = {'foo': 1, 'bar': 2, 'baz': 3}
while d:
print(d.popitem())
print('Done.')
The snippet doesn’t generate any output.
Done.
foo bar baz
('baz', 3)
('bar', 2)
('foo', 1)
Done.
What is the output of this code snippet:
d = {'foo': 1, 'bar': 2, 'baz': 3}
while len(d) > 3:
print(d.popitem())
print('Done.')
Done.
('baz', 3)
('bar', 2)
('foo', 1)
Done.
The snippet doesn’t generate any output.
foo
bar
baz
