wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Final Python Test

Total questions: 103

Worksheet time: 52mins

Name
Class
Date
1.

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

a)

type()

b)

typeof()

c)

object_type()

d)

classof()

2.

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

a)

Error

b)

True

c)

None

d)

False

3.

How do you start a Python script file?

a)

By saving it with a .python extension.

b)

By saving it with a .py extension.

c)

By using #start as the first line.

d)

By running python init in the terminal.

4.

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

a)

[1, 2, 3, 4, 5]

b)

12345

c)

[5, 4, 3, 2, 1]

d)

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

5.

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

a)

+

b)

&

c)

*

d)

!

6.

What does the is operator do in Python?

a)

Assigns a value to a variable.

b)

Tests for membership in a sequence

c)

Compares the values of two variables.

d)

Checks if two variables point to the same object

7.

Which function is used to round a number in Python?

a)

round()

b)

ceil()

c)

floor()

d)

approx()

8.

How do you create an empty set in Python?

a)

set()

b)

{}

c)

[]

d)

()

9.

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

a)

1

b)

1.3333

c)

0.75

d)

Error

10.

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

a)

0

b)

-1

c)

None

d)

Error

11.

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

a)

{key = value}

b)

{'key': 'value'}

c)

['key', 'value']

d)

(key, value)

12.

Which Python keyword is used to create a generator?

a)

return

b)

generate

c)

yield

d)

create

13.

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

14.

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

a)

in

b)

of

c)

has

d)

contains

15.

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

a)

python

b)

PYTHON

c)

Python

d)

None

16.

What is the primary purpose of a variable in Python?

a)

To store data values.

b)

To execute Python code.

c)

To display output on the screen.

d)

To import external libraries.

17.

What is the correct syntax to display "Hello, World!" in Python?

a)

echo "Hello, World!"

b)

print("Hello, World!")

c)

printf("Hello, World!")

d)

System.out.print("Hello, World!")

18.

Which data type is used to store a sequence of characters in Python?

a)

int

b)

list

c)

str

d)

dict

19.

What is the purpose of the input() function in Python?

a)

To take user input.

b)

To define a variable.

c)

To iterate over a sequence.

d)

To display output.

20.

How do you create a list in Python?

a)

my_list = [1, 2, 3]

b)

my_list = {1, 2, 3}

c)

my_list = (1, 2, 3)

d)

my_list = <1, 2, 3>

21.

Which Python operator is used for addition?

a)

*

b)

-

c)

/

d)

+

22.

What is the correct syntax for a while loop in Python?

a)

while x < 10

b)

while x > 10:

c)

repeat while x < 10

d)

while(x > 10)

23.

Which of the following is used to comment out a line in Python?

a)

#

b)

/*

c)

//

d)

<!--

24.

How do you create a function in Python?

a)

def function_name():

b)

function function_name():

c)

function function_name():

d)

create function function_name:

25.

Which Python method can be used to add an item to the end of a list?

a)

insert()

b)

add()

c)

extend()

d)

append()

26.

What is the output of print(2 ** 3)?

a)

8

b)

23

c)

32

d)

6

27.

Which of the following is the correct way to declare a variable that holds a floating-point number in Python?

a)

x = 5.2

b)

x = float(5.2)

c)

float x = 5.2

d)

float x(5.2)

28.

What is the correct way to start a Python program?

a)

def main()

b)

print("Hello, World!")

c)

begin()

d)

start program

29.

How do you create a comment that spans multiple lines in Python?

a)

// comment //

b)

/* comment */

c)

''' comment '''

d)

# comment

30.

Which data type is used to store multiple values in Python?

a)

Float

b)

Integer

c)

List

d)

String

31.

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

a)

input()

b)

read()

c)

scan()

d)

get()

32.

32. What is the correct syntax for a for loop in Python?

a)

for x in range(5):

b)

for x = 1 to 5:

c)

for (x in range(5)):

d)

for x -> 5:

33.

33. Which of these is not a valid Python data type?

a)

char

b)

float

c)

complex

d)

int

34.

34. What will the following Python code output: print("Hello" * 3)?

a)

HelloHelloHello

b)

Hello 3

c)

Hello

d)

Hello Hello Hello

35.

35. Which method is used to remove whitespace from the beginning and end of a string in Python?

a)

strip()

b)

trim()

c)

remove()

d)

cut()

36.

36. How do you write a single-line comment in Python?

a)

# comment

b)

// comment

c)

/* comment */

d)

comment

37.

37. What is the result of 10 % 3 in Python?

a)

1

b)

3

c)

30

d)

0

38.

38. How do you handle exceptions in Python?

a)

try-except

b)

catch-throw

c)

catch-finally

d)

throw-except

39.

39. Which of the following is the correct way to define a class in Python?

a)

class MyClass:

b)

define MyClass

c)

MyClass class:

d)

object MyClass:

40.

40. Which statement is used to exit a loop in Python?

a)

break

b)

exit

c)

end

d)

return

41.

41. Which method is used to add an element to the end of a list?

a)

append()

b)

add()

c)

insert()

d)

extend()

42.

42. What does len() function do in Python?

a)

Returns the length of a string or list.

b)

Converts a string to lowercase.

c)

Adds two strings together.

d)

Returns the number of items in a tuple.

43.

43. Which of the following is the correct way to create a tuple?

a)

my_tuple = (1, 2, 3)

b)

my_tuple = [1, 2, 3]

c)

my_tuple = {1, 2, 3}

d)

my_tuple = 1, 2, 3

44.

44. What is the correct way to check if a value is in a list in Python?

a)

if x in list:

b)

if list.contains(x):

c)

if x in list[]:

d)

if list.includes(x):

45.

45. What does the range() function do in Python?

a)

Generates a list of numbers.

b)

Returns a string from a list.

c)

Reverses a list.

d)

Adds two numbers together.

46.

What is the result of the following code: print("abc" + "def")?

a)

abcdef

b)

abc def

c)

ab cdef

d)

None

47.

Which Python method is used to find the index of an element in a list?

a)

index()

b)

position()

c)

find()

d)

locate()

48.

How do you make a string lowercase in Python?

a)

lower()

b)

to_lower()

c)

downcase()

d)

case_lower()

49.

Which of the following Python functions converts a string to a number?

a)

str()

b)

float()

c)

int()

d)

number()

50.

Which keyword is used to define a function in Python?

a)

define

b)

def

c)

function

d)

func

51.

What will print(2 + 3 * 4) output?

a)

12

b)

18

c)

20

d)

14

52.

What is the output of print(2 == 2)?

a)

Error

b)

None

c)

False

d)

True

53.

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

a)

 []

b)

{}

c)

()

d)

<>

54.

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

a)

my_list[1]

b)

my_list.first()

c)

my_list[1, 2]

d)

my_list[0]

55.

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

a)

if len(string) == 0

b)

if string == ""

c)

if string.empty()

d)

if string is ""

56.

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

a)

None

b)

True

c)

False

d)

Error

57.

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

a)

list(1 to 10)

b)

list(1, 10)

c)

range(1, 11)

d)

range(1, 10)

58.

What does the continue statement do in a loop?

a)

Stops the program.

b)

Exits the loop completely.

c)

Repeats the current iteration.

d)

Skips to the next iteration.

59.

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

a)

object_type()

b)

type()

c)

typeof()

d)

classof()

60.

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

a)

replace()

b)

change()

c)

update()

d)

switch()

61.

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]

62.

Which method removes all items from a list?

a)

delete()

b)

empty()

c)

clear()

d)

empty()

63.

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

a)

insert()

b)

add()

c)

append()

d)

extend()

64.

Which function can convert a list into a set?

a)

convert_set()

b)

set()

c)

make_set()

d)

list_to_set()

65.

What is the purpose of the not keyword in Python?

a)

Compares two values

b)

Assigns a value to a variable

c)

Ends a loop

d)

Reverses the result of a boolean expression

66.

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

a)

<class 'tuple'>

b)

<class 'set'>

c)

<class 'dict'>

d)

<class 'list'>

67.

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

a)

keys()

b)

values()

c)

items()

d)

iterate()

68.

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

a)

2

b)

2.5

c)

Error

d)

3

69.

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

70.

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

a)

Use a try block for each exception.

b)

Write all exceptions on one line separated by semicolons

c)

Use the finally clause

d)

Use multiple except clauses

71.

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

a)

beginwith()

b)

endswith()

c)

startswith()

d)

checkprefix()

72.

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

a)

10

b)

55

c)

Error

d)

5 + 5

73.

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

74.

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

75.

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

a)

anonymous

b)

function

c)

lambda

d)

def

76.

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

a)

2.0

b)

2

c)

4

d)

16

77.

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

a)

values()

b)

keys()

c)

get_keys()

d)

items()

78.

Which data type is unordered in Python?

a)

list

b)

tuple

c)

set

d)

string

79.

What is the default value of a boolean in Python?

a)

True

b)

None

c)

0

d)

False

80.

What will print(bool(0)) output?

a)

False

b)

True

c)

Error

d)

0

81.

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

a)

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

b)

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

c)

write("file.txt")

d)

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

82.

Which Python keyword is used to exit a function?

a)

exit

b)

break

c)

return

d)

stop

83.

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

a)

/t

b)

\n

c)

//

d)

\\

84.

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

a)

3

b)

3.33

c)

10.0

d)

Error

85.

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

a)

int()

b)

convert()

c)

str()

d)

string()

86.

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

a)

find()

b)

index()

c)

count()

d)

repeat()

87.

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.

88.

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

a)

<class 'int'>

b)

<class 'complex'>

c)

<class 'float'>

d)

<class 'decimal'>

89.

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

a)

del

b)

remove()

c)

clear()

d)

pop()

90.

What will be the output of print(type(5)) in Python?

a)

int

b)

<class 'float'>

c)

float

d)

<class 'int'>

91.

Which Python function is used to return the length of a string or list?

a)

count()

b)

len()

c)

length()

d)

size()

92.

Which of these is an immutable data type in Python?

a)

Dictionary

b)

List

c)

Set

d)

Tuple

93.

Which method would you use to remove an item from a list in Python?

a)

discard()

b)

remove()

c)

delete()

d)

remove()

94.

What does the break statement do in Python?

a)

Skips the current iteration.

b)

Moves to the next loop.

c)

Stops the program entirely.

d)

Exits the current loop.

95.

Which of the following is used to import a Python module?

a)

include module_name

b)

import module_name

c)

use module_name

d)

require module_name

96.

Which of the following is the correct syntax for an if statement in Python?

a)

if x > 5:

b)

if x > 5 {}

c)

if x > 5 then:

d)

if (x > 5)

97.

Which operator is used for comparison in Python?

a)

==

b)

=

c)

===

d)

><

98.

What is the correct way to write an else statement in Python?

a)

elseif:

b)

else:

c)

else do:

d)

else if:

99.

Which method in Python is used to convert a string to uppercase?

a)

toUpperCase()

b)

upper()

c)

uppercase()

d)

capitalize()

100.

Which of the following is the correct syntax for defining a class in Python?

a)

define MyClass:

b)

MyClass class:

c)

class MyClass:

d)

class MyClass():

101.

What does the continue statement do in a loop in Python?

a)

Exits the loop completely.

b)

Skips the rest of the current loop iteration.

c)

Breaks the loop and goes to the next statement.

d)

Restarts the loop from the beginning.

102.

Which of these is a valid way to create a dictionary in Python?

a)

my_dict = ('key1', 'value1')

b)

my_dict = {'key1': 'value1', 'key2': 'value2'}

c)

my_dict = ('key1': 'value1')

d)

my_dict = ['key1', 'value1']

103.

What will be the output of print(5 // 2)?

a)

2.5

b)

3

c)

5

d)

2