wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python

Total questions: 57

Worksheet time: 29mins

Name
Class
Date
1.

Which of the following is used to define a dictionary in Python?

a)

{}

b)

[]

c)

()

d)

<>

2.

How do you access the first element of a list my_list = [10, 20, 30]?

a)

my_list[1, 2]

b)

my_list.first()

c)

my_list[1]

d)

my_list[0]

3.

How do you check if a string is empty in Python?

a)

if string.empty()

b)

if string == ""

c)

if string is ""

d)

if len(string) == 0

4.

What will print("Python" == "python") output?

a)

False

b)

True

c)

None

d)

Error

5.

Which of the following will create a list of numbers from 1 to 10 in Python?

a)

list(1, 10)

b)

range(1, 10)

c)

range(1, 11)

d)

list(1 to 10)

6.

Which method is used to remove an item from a dictionary in Python?

a)

remove()

b)

pop()

c)

delete()

d)

discard()

7.

What does the continue statement do in a loop?

a)

Exits the loop completely.

b)

Repeats the current iteration.

c)

Stops the program.

d)

Skips to the next iteration.

8.

Which function is used to determine the type of an object in Python?

a)

typeof()

b)

object_type()

c)

type()

d)

classof()

9.

What will the following code output? print(bool(""))

a)

False

b)

True

c)

None

d)

Error

10.

How do you start a Python script file?

a)

By saving it with a .py extension.

b)

By saving it with a .python extension.

c)

By using #start as the first line.

d)

By running python init in the terminal.

11.

What will print([1, 2, 3] + [4, 5]) output?

a)

12345

b)

[1, 2, 3, 4, 5]

c)

[5, 4, 3, 2, 1]

d)

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

12.

Which operator is used to repeat a string multiple times in Python?

a)

!

b)

&

c)

+

d)

*

13.

What does the is operator do in Python?

a)

Tests for membership in a sequence.

b)

Assigns a value to a variable.

c)

Compares the values of two variables.

d)

Checks if two variables point to the same object.

14.

Which function is used to round a number in Python?

a)

ceil()

b)

round()

c)

floor()

d)

approx()

15.

How do you create an empty set in Python?

a)

 ()

b)

[]

c)

set()

d)

{}

16.

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

a)

1.3333

b)

1

c)

0.75

d)

Error

17.

What will print("Python".find("P")) output?

a)

None

b)

-1

c)

0

d)

Error

18.

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

a)

{'key': 'value'}

b)

{key = value}

c)

['key', 'value']

d)

(key, value)

19.

Which Python keyword is used to create a generator?

a)

generate

b)

generate

c)

return

d)

yield

20.

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.

21.

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

a)

of

b)

in

c)

has

d)

contains

22.

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

a)

PYTHON

b)

python

c)

Python

d)

None

23.

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

a)

replace()

b)

change()

c)

update()

d)

switch()

24.

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

a)

[1, 2, 3, 4, 5]

b)

[5, 4, 3, 2, 1]

c)

[0, 1, 2, 3, 4]

d)

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

25.

Which method removes all items from a list?

a)

empty()

b)

remove_all()

c)

delete()

d)

clear()

26.

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

a)

insert()

b)

add()

c)

append()

d)

extend()

27.

Which function can convert a list into a set?

a)

set()

b)

convert_set()

c)

make_set()

d)

list_to_set()

28.

What is the purpose of the not keyword in Python?

a)

Ends a loop.

b)

Compares two values.

c)

Assigns a value to a variable.

d)

Reverses the result of a boolean expression.

29.

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

a)

<class 'tuple'>

b)

<class 'list'>

c)

<class 'set'>

d)

<class 'dict'>

30.

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

a)

keys()

b)

items()

c)

values()

d)

iterate()

31.

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

a)

Error

b)

3

c)

2

d)

 2.5

32.

Which of the following represents a valid Python module?

a)

A .txt file containing text.

b)

A .exe file containing executable code.

c)

A .py file containing Python code.

d)

A .csv file containing comma-separated values.

33.

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

a)

Use the finally clause.

b)

Use multiple except clauses.

c)

Use a try block for each exception.

d)

Write all exceptions on one line separated by semicolons.

34.

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

a)

startswith()

b)

endswith()

c)

checkprefix()

d)

beginwith()

35.

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

a)

Error

b)

5+5

c)

10

d)

55

36.

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"""

37.

What does the enumerate() function do in Python?

a)

Sorts a list.

b)

Reverses a list.

c)

Filters elements in a list.

d)

Returns pairs of indices and elements from a sequence.

38.

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

a)

def

b)

anonymous

c)

lambda

d)

function

39.

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

a)

2

b)

2.0

c)

4

d)

16

40.

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

a)

get_keys()

b)

keys()

c)

values()

d)

items()

41.

Which data type is unordered in Python?

a)

set

b)

list

c)

tuple

d)

string

42.

What is the default value of a boolean in Python?

a)

0

b)

True

c)

None

d)

 False

43.

What will print(bool(0)) output?

a)

0

b)

Error

c)

True

d)

 False

44.

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

a)

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

b)

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

c)

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

d)

write("file.txt")

45.

Which Python keyword is used to exit a function?

a)

break

b)

exit

c)

return

d)

stop

46.

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

a)

//

b)

\n

c)

\t

d)

\\

47.

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

a)

3

b)

3.33

c)

10.0

d)

Error

48.

What will print(type([])) output?

a)

<class 'list'>

b)

<class 'tuple'>

c)

<class 'dict'>

d)

<class 'set'>

49.

Which function is used to convert a number to a string in Python?

a)

int()

b)

str()

c)

string()

d)

float()

50.

What is the default starting index for Python lists?

a)

1

b)

0

c)

-1

d)

None

51.

How do you remove an element by its index from a list?

a)

remove(index)

b)

delete(index)

c)

discard(index)

d)

pop(index)

52.

What does the max() function do?

a)

Returns the total count of elements.

b)

Returns the largest item in an iterable.

c)

Converts numbers to the largest integer.

d)

Removes the largest value.

53.

Which keyword is used to create a loop that continues as long as a condition is true?

a)

for

b)

if

c)

while

d)

continue

54.

What will print("hello".capitalize()) output?

a)

HELLO

b)

 hello

c)

Hello

d)

None

55.

What is the result of print(4 < 2 or 3 > 1)?

a)

True

b)

False

c)

None

d)

Error

56.

What does the split() method do?

a)

Reverses the string.

b)

Removes spaces from the string.

c)

Combines multiple strings into one.

d)

Splits a string into a list of substrings.

57.

How do you check the number of elements in a list?

a)

len(list)

b)

size(list)

c)

count(list)

d)

length(list)