wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Final

Total questions: 124

Worksheet time: 1hrs 2mins

Name
Class
Date
1.

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.

2.

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

a)

print("Hello, World!")

b)

echo "Hello, World!"

c)

printf("Hello, World!")

d)

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

3.

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

a)

str

b)

int

c)

list

d)

dict

4.

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.

5.

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>

6.

Which Python operator is used for addition?

a)

+

b)

-

c)

*

d)

/

7.

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

a)

while x > 10:

b)

while(x > 10)

c)

while x < 10

d)

repeat while x < 10

8.

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

a)

#

b)

/*

c)

//

d)

<!--

9.

How do you create a function in Python?

a)

def function_name():

b)

function function_name():

c)

func function_name():

d)

create function function_name:

10.

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

a)

append()

b)

insert()

c)

add()

d)

extend()

11.

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

a)

8

b)

6

c)

23

d)

32

12.

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)

float x = 5.2

c)

x = float(5.2)

d)

float x(5.2)

13.

What is the correct way to start a Python program?

a)

print("Hello, World!")

b)

def main()

c)

start program

d)

begin()

14.

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

a)

''' comment '''

b)

// comment //

c)

/* comment */

d)

# comment

15.

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

a)

List

b)

String

c)

Integer

d)

Float

16.

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

a)

<class 'int'>

b)

<class 'float'>

c)

int

d)

float

17.

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

a)

len()

b)

size()

c)

count()

d)

length()

18.

Which of these is an immutable data type in Python?

a)

Tuple

b)

List

c)

Dictionary

d)

Set

19.

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

a)

remove()

b)

pop()

c)

delete()

d)

discard()

20.

What does the break statement do in Python?

a)

Exits the current loop.

b)

Stops the program entirely.

c)

Skips the current iteration.

d)

Moves to the next loop.

21.

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

a)

import module_name

b)

require module_name

c)

include module_name

d)

use module_name

22.

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 {}

23.

Which operator is used for comparison in Python?

a)

==

b)

=

c)

><

d)

===

24.

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

a)

else:

b)

else if:

c)

elseif:

d)

else do:

25.

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

a)

upper()

b)

toUpperCase()

c)

capitalize()

d)

uppercase()

26.

Which statement is used to handle exceptions in Python?

a)

try-except

b)

catch

c)

error

d)

throw

27.

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

a)

Skips the rest of the current loop iteration.

b)

Exits the loop completely.

c)

Restarts the loop from the beginning.

d)

Breaks the loop and goes to the next statement.

28.

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

a)

class MyClass:

b)

MyClass class:

c)

define MyClass:

d)

class MyClass():

29.

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

a)

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

b)

my_dict = ('key1', 'value1')

c)

my_dict = ['key1', 'value1']

d)

my_dict = ('key1': 'value1')

30.

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

a)

2

b)

2.5

c)

3

d)

5

31.

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

a)

input()

b)

read()

c)

scan()

d)

get()

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.

Which of these is not a valid Python data type?

a)

char

b)

float

c)

complex

d)

int

34.

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

a)

HelloHelloHello

b)

Hello 3

c)

Hello

d)

Hello Hello Hello

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.

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

a)

# comment

b)

// comment

c)

/* comment */

d)

comment

37.

What is the result of 10 % 3 in Python?

a)

1

b)

3

c)

30

d)

0

38.

How do you handle exceptions in Python?

a)

try-except

b)

catch-throw

c)

catch-finally

d)

throw-except

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.

Which statement is used to exit a loop in Python?

a)

break

b)

exit

c)

end

d)

return

41.

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

a)

append()

b)

add()

c)

insert()

d)

extend()

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.

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.

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.

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)

int()

b)

float()

c)

str()

d)

number()

50.

Which keyword is used to define a function in Python?

a)

def

b)

function

c)

func

d)

define

51.

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

a)

14

b)

20

c)

18

d)

12

52.

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

a)

True

b)

False

c)

None

d)

Error

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[0]

b)

my_list[1]

c)

my_list.first()

d)

my_list[1, 2]

55.

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

a)

if string == ""

b)

if string.empty()

c)

if string is ""

d)

if len(string) == 0

56.

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

a)

False

b)

True

c)

None

d)

Error

57.

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

a)

range(1, 11)

b)

list(1, 10)

c)

range(1, 10)

d)

list(1 to 10)

58.

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

a)

pop()

b)

remove()

c)

delete()

d)

discard()

59.

What does the continue statement do in a loop?

a)

Skips to the next iteration.

b)

Exits the loop completely.

c)

Repeats the current iteration.

d)

Stops the program.

60.

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

a)

type()

b)

typeof()

c)

object_type()

d)

classof()

61.

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

a)

False

b)

True

c)

None

d)

Error

62.

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.

63.

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]

64.

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

a)

*

b)

+

c)

&

d)

!

65.

What does the is operator do in Python?

a)

Checks if two variables point to the same object.

b)

Compares the values of two variables.

c)

Assigns a value to a variable.

d)

Tests for membership in a sequence.

66.

Which function is used to round a number in Python?

a)

round()

b)

ceil()

c)

floor()

d)

approx()

67.

How do you create an empty set in Python?

a)

set()

b)

{}

c)

[]

d)

()

68.

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

a)

1

b)

1.3333

c)

0.75

d)

0.75

69.

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

a)

0

b)

-1

c)

None

d)

Error

70.

Which Python keyword is used to create a generator?

a)

yield

b)

return

c)

generate

d)

create

71.

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.

72.

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

a)

{'key': 'value'}

b)

{key = value}

c)

['key', 'value']

d)

(key, value)

73.

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

a)

in

b)

of

c)

has

d)

contains

74.

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

a)

python

b)

PYTHON

c)

Python

d)

None

75.

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

a)

replace()

b)

change()

c)

update()

d)

switch()

76.

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]

77.

Which method removes all items from a list?

a)

clear()

b)

delete()

c)

remove_all()

d)

empty()

78.

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

a)

add()

b)

insert()

c)

append()

d)

extend()

79.

Which function can convert a list into a set?

a)

set()

b)

convert_set()

c)

make_set()

d)

list_to_set()

80.

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.

81.

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

a)

<class 'list'>

b)

<class 'tuple'>

c)

<class 'set'>

d)

<class 'dict'>

82.

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

a)

items()

b)

keys()

c)

values()

d)

iterate()

83.

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

a)

2.5

b)

2

c)

Error

d)

3

84.

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.

85.

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.

86.

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

a)

startswith()

b)

endswith()

c)

checkprefix()

d)

beginwith()

87.

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

a)

55

b)

10

c)

Error

d)

5 + 5

88.

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 */

89.

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.

90.

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

a)

lambda

b)

function

c)

def

d)

anonymous

91.

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

a)

2.0

b)

2

c)

4

d)

16

92.

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

a)

keys()

b)

values()

c)

items()

d)

get_keys()

93.

Which data type is unordered in Python?

a)

set

b)

list

c)

tuple

d)

string

94.

What is the default value of a boolean in Python?

a)

False

b)

None

c)

True

d)

0

95.

What will print(bool(0)) output?

a)

False

b)

True

c)

Error

d)

0

96.

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

97.

Which Python keyword is used to exit a function?

a)

return

b)

break

c)

exit

d)

stop

98.

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

a)

\n

b)

\t

c)

\\

d)

//

99.

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

a)

3

b)

3.33

c)

10.0

d)

Error

100.

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

a)

<class 'list'>

b)

<class 'tuple'>

c)

<class 'dict'>

d)

<class 'set'>

101.

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

a)

str()

b)

int()

c)

string()

d)

float()

102.

What is the default starting index for Python lists?

a)

0

b)

1

c)

-1

d)

None

103.

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

a)

pop(index)

b)

remove(index)

c)

delete(index)

d)

discard(index)

104.

What does the max() function do?

a)

Returns the largest item in an iterable.

b)

Returns the total count of elements.

c)

Converts numbers to the largest integer.

d)

Removes the largest value.

105.

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

a)

while

b)

for

c)

continue

d)

if

106.

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

a)

Hello

b)

HELLO

c)

hello

d)

None

107.

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

a)

True

b)

False

c)

None

d)

Error

108.

What does the split() method do?

a)

Splits a string into a list of substrings.

b)

Reverses the string.

c)

Combines multiple strings into one.

d)

Removes spaces from the string.

109.

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

a)

len(list)

b)

size(list)

c)

count(list)

d)

length(list)

110.

Which of the following is a valid Python variable name?

a)

my_var

b)

2ndVar

c)

my-var

d)

my var

111.

Which Python method converts a list into a string with a delimiter?

a)

join()

b)

split()

c)

combine()

d)

merge()

112.

What is the correct way to get the last element of a list?

a)

my_list[-1]

b)

my_list[0]

c)

my_list[last]

d)

my_list[1:]

113.

What does the startswith() method check in a string?

a)

If the string starts with a specified substring.

b)

If the string is uppercase.

c)

If the string contains whitespace.

d)

If the string is alphanumeric.

114.

What will print("a" in "apple") output?

a)

True

b)

False

c)

Error

d)

None

115.

How do you access the value associated with a key in a dictionary?

a)

dict[key]

b)

dict.value(key)

c)

dict(key)

116.

Which function is used to sort a list permanently in Python?

a)

sort()

b)

sorted()

c)

order()

d)

arrange()

117.

What is the output of print(bool(0))?

a)

False

b)

True

c)

Error

d)

None

118.

Which of the following is NOT a valid Python loop?

a)

do-while

b)

while

c)

for

d)

nested for

119.

What is the result of the following code? print(5 in [1, 2, 3, 4, 5])

a)

True

b)

False

c)

None

d)

Error

120.

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

a)

str()

b)

int()

c)

convert()

d)

string()

121.

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

a)

count()

b)

find()

c)

index()

d)

repeat()

122.

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.

123.

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

a)

<class 'float'>

b)

<class 'int'>

c)

<class 'complex'>

d)

<class 'decimal'>

124.

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

a)

pop()

b)

remove()

c)

del

d)

clear()