Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Fundamentals Assessment

Total questions: 20

Worksheet time: 32mins

Name
Class
Date
1.

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)

a)

[10, 'a'] [123] [10, 'a']

b)

[10] [123] ['a']

c)

[10, 'a'] [123] [10, 'a']

d)

[10, 'a'] [123, 'a'] ['a']

2.

What will be printed?

class A:

x = []

a1 = A()

a2 = A()

a1.x.append(1)

print(a1.x, a2.x, A.x)

a)

[1] [] [1]

b)

[1] [1] [1]

c)

[1] [] []

d)

[] [1] [1]

3.

What is the result?

x = 1000

y = 1000

a = 257

b = 257

print(x is y, a is b)

a)

True True

b)

True False

c)

False True

d)

functionFalse False

4.

What is printed?

def f():

try:

1/0

except:

return "except"

finally:

return "finally"

print(f())

a)

except

b)

finally

c)

except finally

d)

Raises ZeroDivisionError

5.

What will this code output?

def multiplier(n):

def inner(x):

return x * n

n += 1

return inner

f = multiplier(5)

print(f(10))

a)

50

b)

60

c)

55

d)

10

6.

What is the output?

d = {}

d[1] = "int"

d[1.0] = "float"

d[True] = "bool"

print(len(d))

a)

1

b)

2

c)

3

d)

TypeError

7.

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())

a)

[0, 1, 4]

b)

Error – unbound local variable

c)

[0, 1, 4, 9]

d)

[]

8.

How do you add an element to a set in Python?

a)

Add elements using the append() function, e.g., my_set.append(element).

b)

Use the add() method, e.g., my_set.add(element).

c)

Utilize the push() method, e.g., my_set.push(element).

d)

Use the insert() method, e.g., my_set.insert(element).

9.

Which line does NOT raise an error?

t = (1, [2, 3], 4)

a)

t[1].append(99)

b)

t[1] = [5,6]

c)

t[0] = 100

d)

t[1][0] = 777

10.
  1. 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)

a)

3 2

b)

2 2

c)

3 3

d)

4 2

11.

Which statement best describes Python's "first-class functions" property?

a)

Functions can be passed as arguments, returned from functions, and assigned to variables

b)

Functions can only be defined at module level

c)
  1. Functions are executed immediately when defined

These questions test deep conceptual understanding rather than just syntax knowledge. Good luck with your preparation! 🐍

d)

Functions cannot be nested

12.

What is the output?

for i in range(3):

print(i)

else:

print("Done")

a)

012

b)

Done

c)

0 1 2 Done

d)

Done 0 1 2

13.
  1. Python is a ________ typed language.

a)
  1. Statically

b)
  1. Dynamically

c)
  1. Strongly but not dynamically

d)
  1. Weakly

14.

Which data structure does NOT allow duplicate elements?

a)

List

b)

Tuple

c)

Set

d)

Dictionary values

15.

Which loop is guaranteed to execute at least once?

a)

for

b)

while

c)

do-while

d)

Python has no such loop

16.

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)

a)

[1, 3, 4, 5]

b)

[3, 4, 1, 5]

c)

[4, 4, 1, 5]

d)

[3, 1, 4, 5]

17.

What is the output of the following code: print(5 == 5 and 3 > 2)?

a)

Maybe

b)

None

c)

False

d)

True

18.

Which function is used to read input from the user in Python?

a)

get_input()

b)

fetch_input()

c)

input()

d)

read_input()

19.

What is the purpose of the 'elif' statement in Python?

a)

The 'elif' statement is a way to create comments in Python.

b)

The 'elif' statement allows for multiple conditional checks in an if-else structure.

c)

The 'elif' statement terminates a loop in Python.

d)

The 'elif' statement is used to define functions in Python.

20.

How do you create a dictionary in Python?

a)

A dictionary in Python is created with parentheses, for example: my_dict = ('key1', 'value1', 'key2', 'value2').

b)

You can create a dictionary in Python using curly braces, like this: my_dict = {'key1': 'value1', 'key2': 'value2'}.

c)

To create a dictionary in Python, use a list, like this: my_dict = ['key1', 'value1', 'key2', 'value2'].

d)

You can create a dictionary in Python using square brackets, like this: my_dict = ['key1': 'value1', 'key2': 'value2'].