Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python 71-105

Total questions: 35

Worksheet time: 18mins

Name
Class
Date
1.

What is the correct way to define a dictionary in Python?

a)

{'key': 'value'}

b)

{key = value}

c)

['key', 'value']

d)

(key, value)

2.

Which Python keyword is used to create a generator?

a)

yield

b)

return

c)

generate

d)

create

3.

What does list.pop() do?

a)

Removes and returns the last item in a list.

b)

Adds an item to the end of a list.

c)

Removes an item by index.

d)

Clears the list.

4.

Which keyword is used to check for membership in a sequence?

a)

in

b)

of

c)

has

d)

contains

5.

What is the output of print("PYTHON".lower())?

a)

python

b)

PYTHON

c)

Python

d)

None

6.

Which Python method is used to replace parts of a string?

a)

replace()

b)

change()

c)

update()

d)

switch()

7.

What will print(list(range(5))) output?

a)

[0, 1, 2, 3, 4]

b)

[1, 2, 3, 4, 5]

c)

[5, 4, 3, 2, 1]

d)

[0, 1, 2, 3, 4, 5]

8.

Which method removes all items from a list?

a)

clear()

b)

delete()

c)

remove_all()

d)

empty()

9.

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

a)

add()

b)

insert()

c)

append()

d)

extend()

10.

Which function can convert a list into a set?

a)

set()

b)

convert_set()

c)

make_set()

d)

list_to_set()

11.

What is the purpose of the not keyword in Python?

a)

Reverses the result of a boolean expression.

b)

Compares two values.

c)

Assigns a value to a variable.

d)

Ends a loop.

12.

What is the output of print(type([1, 2, 3]))?

a)

<class 'list'>

b)

<class 'tuple'>

c)

<class 'set'>

d)

<class 'dict'>

13.

Which function can you use to iterate over both keys and values of a dictionary?

a)

items()

b)

keys()

c)

values()

d)

iterate()

14.

What will the following code output? print(10 / 4)

a)

2.5

b)

2

c)

Error

d)

3

15.

Which of the following represents a valid Python module?

a)

A .py file containing Python code.

b)

A .txt file containing text.

c)

A .exe file containing executable code.

d)

A .csv file containing comma-separated values.

16.

How do you handle multiple exceptions in a single try block?

a)

Use multiple except clauses.

b)

Use a try block for each exception.

c)

Write all exceptions on one line separated by semicolons.

d)

Use the finally clause.

17.

Which of the following will check if a string starts with a specific prefix?

a)

startswith()

b)

endswith()

c)

checkprefix()

d)

beginwith()

18.

What will print("5" + "5") output?

a)

55

b)

10

c)

Error

d)

5 + 5

19.

What is the correct way to define a multi-line string in Python?

a)

"""This is a multi-line string"""

b)

// This is a multi-line string //

c)

## This is a multi-line string ##

d)

/** This is a multi-line string */

20.

What does the enumerate() function do in Python?

a)

Returns pairs of indices and elements from a sequence.

b)

Sorts a list.

c)

Reverses a list.

d)

Filters elements in a list.

21.

Which keyword is used to define an anonymous function in Python?

a)

lambda

b)

function

c)

def

d)

anonymous

22.

What is the output of print(4 ** 0.5)?

a)

2.0

b)

2

c)

4

d)

16

23.

Which method is used to get all the keys of a dictionary?

a)

keys()

b)

values()

c)

items()

d)

get_keys()

24.

Which data type is unordered in Python?

a)

set

b)

list

c)

tuple

d)

string

25.

What is the default value of a boolean in Python?

a)

False

b)

None

c)

True

d)

0

26.

What will print(bool(0)) output?

a)

False

b)

True

c)

Error

d)

0

27.

What is the correct way to open a file for writing in Python?

a)

open("file.txt", "w")

b)

open("file.txt", "r")

c)

open("file.txt", "a")

d)

write("file.txt")

28.

Which Python keyword is used to exit a function?

a)

return

b)

break

c)

exit

d)

stop

29.

How do you create a new line in a string in Python?

a)

\n

b)

\t

c)

\\

d)

//

30.

What is the output of print(10 // 3)?

a)

3

b)

3.33

c)

10.0

d)

Error

31.

Which Python function can be used to convert an integer to a string?

a)

str()

b)

int()

c)

convert()

d)

string()

32.

Which method is used to count the number of occurrences of a substring in a string?

a)

count()

b)

find()

c)

index()

d)

repeat()

33.

What does the pass keyword do in Python?

a)

Acts as a placeholder and does nothing.

b)

Skips the next iteration of a loop.

c)

Ends the execution of a function.

d)

Raises an exception.

34.

What will the following code output? print(type(10.5))

a)

<class 'float'>

b)

<class 'int'>

c)

<class 'complex'>

d)

<class 'decimal'>

35.

Which Python method removes an item by its index from a list?

a)

pop()

b)

remove()

c)

del

d)

clear()