WorksheetsPython Fundamentals Assessment
Total questions: 20
Worksheet time: 32mins
What is the output?
def extendList(val, list=[]):
list.append(val)
return list
l1 = extendList(10)
l2 = extendList(123,[])
l3 = extendList('a')
print(l1, l2, l3)
[10, 'a'] [123] [10, 'a']
[10] [123] ['a']
[10, 'a'] [123] [10, 'a']
[10, 'a'] [123, 'a'] ['a']
What will be printed?
class A:
x = []
a1 = A()
a2 = A()
a1.x.append(1)
print(a1.x, a2.x, A.x)
[1] [] [1]
[1] [1] [1]
[1] [] []
[] [1] [1]
What is the result?
x = 1000
y = 1000
a = 257
b = 257
print(x is y, a is b)
True True
True False
False True
functionFalse False
What is printed?
def f():
try:
1/0
except:
return "except"
finally:
return "finally"
print(f())
except
finally
except finally
Raises ZeroDivisionError
What will this code output?
def multiplier(n):
def inner(x):
return x * n
n += 1
return inner
f = multiplier(5)
print(f(10))
50
60
55
10
What is the output?
d = {}
d[1] = "int"
d[1.0] = "float"
d[True] = "bool"
print(len(d))
1
2
3
TypeError
What will be printed?
def outer():
result = []
def inner(x):
result.append(x**2)
for i in range(3):
inner(i)
return result
print(outer())
[0, 1, 4]
Error – unbound local variable
[0, 1, 4, 9]
[]
How do you add an element to a set in Python?
Add elements using the append() function, e.g., my_set.append(element).
Use the add() method, e.g., my_set.add(element).
Utilize the push() method, e.g., my_set.push(element).
Use the insert() method, e.g., my_set.insert(element).
Which line does NOT raise an error?
t = (1, [2, 3], 4)
t[1].append(99)
t[1] = [5,6]
t[0] = 100
t[1][0] = 777
What will be printed?
Pythondef func(x, y=2, args, *kwargs):
print(len(args), len(kwargs))
func(1, 2, 3, 4, 5, a=10, b=20)
3 2
2 2
3 3
4 2
Which statement best describes Python's "first-class functions" property?
Functions can be passed as arguments, returned from functions, and assigned to variables
Functions can only be defined at module level
Functions are executed immediately when defined
These questions test deep conceptual understanding rather than just syntax knowledge. Good luck with your preparation! 🐍
Functions cannot be nested
What is the output?
for i in range(3):
print(i)
else:
print("Done")
012
Done
0 1 2 Done
Done 0 1 2
Python is a ________ typed language.
Statically
Dynamically
Strongly but not dynamically
Weakly
Which data structure does NOT allow duplicate elements?
List
Tuple
Set
Dictionary values
Which loop is guaranteed to execute at least once?
for
while
do-while
Python has no such loop
WHAT IS THE OUTPUT ?
data = [1, 2, 3]
result = []
for i in range(len(data)):
temp = []
for j in range(i, len(data)):
if data[j] % 2 == 0:
temp.append(data[j] * 2)
else:
temp.append(data[j] + i)
if sum(temp) > 10:
result.append(temp)
else:
result.append(temp[::-1])
final = []
for item in result:
for val in item:
if val not in final:
final.append(val)
print(final)
[1, 3, 4, 5]
[3, 4, 1, 5]
[4, 4, 1, 5]
[3, 1, 4, 5]
What is the output of the following code: print(5 == 5 and 3 > 2)?
Maybe
None
False
True
Which function is used to read input from the user in Python?
get_input()
fetch_input()
input()
read_input()
What is the purpose of the 'elif' statement in Python?
The 'elif' statement is a way to create comments in Python.
The 'elif' statement allows for multiple conditional checks in an if-else structure.
The 'elif' statement terminates a loop in Python.
The 'elif' statement is used to define functions in Python.
How do you create a dictionary in Python?
A dictionary in Python is created with parentheses, for example: my_dict = ('key1', 'value1', 'key2', 'value2').
You can create a dictionary in Python using curly braces, like this: my_dict = {'key1': 'value1', 'key2': 'value2'}.
To create a dictionary in Python, use a list, like this: my_dict = ['key1', 'value1', 'key2', 'value2'].
You can create a dictionary in Python using square brackets, like this: my_dict = ['key1': 'value1', 'key2': 'value2'].
