WorksheetsTech Python
Total questions: 30
Worksheet time: 15mins
Which of the following is NOT a programming paradigm?
Object Oriented
Functional
Procedural
Relational
Which of the following is immutable?(more than 1 correct answer)
Tuple
String
List
Int
What is the OUTPUT?
print([] is [])
True
False
Error
None
Which of the following is not a valid Python data type?
list
tuple
array
set
What is the output?
print(len([[]]))
0
1
2
Error
What is the OUTPUT?
print(type({1,2,3}))
list
tuple
set
dict
What is the OUTPUT?
print(0.1 + 0.2 == 0.3)
True
False
Error
None
What does pass do in Python?
Stops loop
Skips iteration
Does nothing
Raises error
x = 10
def f(y=x):
return y
x = 20
print(f())
What is the OUTPUT?
(a)
a=257
b=257
print(a is b)
What is the OUTPUT?
True
False
Error
None
def pack(item, sack=[]):
sack += [item]
return sack
print(pack("toy"))
print(pack("book"))
What is the OUTPUT?
["toy"], ["toy", "book"]
["toy"], ["book"]
Error
Empty list
kids = {True: "Nice", 1: "Naughty", 1.0: "??? "}
print(len(kids))
What is the OUTPUT?
(a)
print([] == False)
What is the OUTPUT?
True
False
Error
None
a = [1, 2, 3]
b = a
a += [4, 5]
print(b)
What is the OUTPUT?
[1,2,3]
Error
[1,2,3,4,5]
[1,2]
print([i for i in range(3)] is [i for i in range(3)])
What is the OUTPUT?
(a)
What is the OUTPUT?
print(type(type(int)))
int
class
type
error
def test():
try:
return 1
except:
return 2
finally:
return 3
What is the OUTPUT?
1 2 3
1 2
3
1 2
3
What is the OUTPUT?
print(True + True)
True
1
2
0
Error
x = [[0]] * 3
x[0][0] = 1
print(x)
What is the OUTPUT?
[[1],[3],[3]]
[1],[3],[3]
[[3],[3],[3]]
[[1],[1],[1]]
[1],[1],[1]
x = 10
x = "Python"
print(x)
What is the OUTPUT?
10
Python
Error
None
def f(x=[]):
x.append(1)
print(x)
f()
f()
What is the OUTPUT?
[1] [1]
[1] [1,1]
[1] [11]
[11]
[1], [11]
What is the output?
x = 10
def f():
print(x)
x = 5
f()
10
5
UnboundLocalError
NULL
Which bug exists in this code?
def add(item, lst=[]):
lst.append(item)
return lst
Syntax error
Logical error due to mutable default argument
Runtime error
No error
What is the OUTPUT?
print(False == False in [False])
True
False
Error
None
What is the output?
x = 1
def f():
return x
def g():
x = 2
return f()
print(g())
(a)
What is the output?
x = [[1]] * 3
x[0][0] = 9
print(x)
[9],[1],[1]
[9],[9],[9]
[[9],[1],[1]]
[[9],[9],[9]]
What is the output?
print([] or {} and ())
[]
{} or ()
()
[] or ()
Error
Which operator is used for floor division?
(a)
What is the output?
a = [1, 2, 3]
b = a
b.append(4)
print(a)
[1, 2, 3]
[1, 2, 3, 4]
Error
[4]
What will be printed?
x = [i*i for i in range(3)]
print(x)
[1, 4, 9]
[0, 1, 4]
[0, 1, 2]
Error
