NEW
Font size
WorksheetsPython Programming Quiz
Total questions: 15
Worksheet time: 8mins
Which of the following data types is mutable in Python?
String
Tuple
List
Frozenset
What will be the output of the following code snippet? def func(x=[]): x.append(1) return x print(func()) print(func())
[1] [1]
[1] [1, 1]
[1, 1] [1, 1]
Syntax Error
What will be the output of the following code? x = [1, 2, 3, 4] y = x y.append(5) print(x)
[1, 2, 3, 4]
[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5, 5]
[5]
What will be the output of the following code snippet? print("Hello, World!"[::-1])
"dlroW ,olleH"
"Hello, World!"
Error
None
What is the output of the following code? x = {1, 2, 3, 4} x.add(4) print(len(x))
3
4
5
Error
Which of the following statements is incorrect about Python dictionaries?
Keys must be unique.
Values must be unique.
Keys must be immutable.
Values can be of any data type.
What does the lambda keyword in Python define?
A class
A function
A module
A loop
Which of the following methods will convert a list into a tuple?
list()
dict()
tuple()
set()
What will be the output of the following code snippet? x = [1, 2, 3] y = x * 2 print(y)
[1, 2, 3]
[1, 2, 3, 1, 2, 3]
Error
[[1, 2, 3], [1, 2, 3]]
What does the following Python expression evaluate to? bool([]) and bool("")
True
False
Syntax Error
Type Error
What is the output of the following code? a = (1, 2) a[0] = 5
(5, 2)
(1, 2)
Error
(1, 5)
Which of the following statements about the continue statement is true?
It terminates the loop.
It skips the rest of the code inside the loop for the current iteration.
It moves to the previous iteration.
It raises an error if used inside a loop.
What will be the output of the following code snippet? def f(x, y=[]): y.append(x) return y print(f(1)) print(f(2))
[1] [2]
[1] [1, 2]
[1, 2] [1, 2]
Error
Which of the following operators cannot be overloaded in Python?
+
//
==
and
What is the result of the following code? a = {1, 2, 3} b = {3, 4, 5} print(a & b)
{1, 2, 3, 4, 5}
{3}
{1, 2}
{}
