wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Final

Total questions: 74

Worksheet time: 37mins

Name
Class
Date
1.

What is the correct data type for a whole number in Python?

a)

A) Integer

b)

B) Float

c)

C) String

d)

D) Boolean

2.

How do you declare a string variable in Python?

a)

A) var_name = 42

b)

B) var_name = 3.14

c)

C) var_name = "Hello"

d)
  •  var_name = True

3.

Which function is used to take user input in Python?

a)

A) input()

b)

B) print()

c)

C) read()

d)

D) get()

4.

What does the print() function do in Python?

a)

A) Takes user input

b)

B) Displays output on the console

c)

C) Performs mathematical operations

d)

D) Defines a function

5.

What does the // operator do in Python?

a)

A) Floor division

b)

B) Exponentiation

c)

C) Modulus

d)

D) Addition

6.
  1.  result = 5 + 3 * 2

  • print(result)

a)

A) 16

b)

B) 11

c)

C) 13

d)

D) 26

7.

What is the value of the expression True and False?

a)

A) True

b)

B) False

c)

C) Error

d)

D) None

8.

Which of the following represents a Boolean value in Python?

a)

A) "Hello"

b)

B) 42

c)

C) 3.14

d)

D) True

9.

How is an if statement written in Python?

a)

A) if condition:

b)

B) if then:

c)

C) if (condition)

d)

D) condition if

10.

What is the purpose of the else statement in Python?

a)

A) To define a function

b)

B) To handle exceptions

c)

C) To execute code when the if condition is False

d)

D) To perform mathematical operations

11.

What does the break statement do in a loop?

a)

Skips the current iteration and continues with the next one

b)

Immediately terminates the loop and continues with the next statement after the loop

c)

Restarts the loop from the beginning

d)

Pauses the loop execution temporarily

12.

How do you add an element to the end of a list in Python?

a)

A) list.append()

b)

B) list.insert()

c)

C) list.extend()

d)

D) list.add()

13.

In Python, what does a for loop iterate over?

a)

A) Indices of a list

b)

B) Characters in a string

c)

C) Elements of a sequence

d)

D) All of the above

14.

What is the main difference between list and tuple?

a)

A) Lists are mutable; tuples are immutable

b)

B) Lists are of fixed size; tuples can grow or shrink

c)

C) Lists can only store integers; tuples can store any data type

d)

D) Lists can have duplicate elements; tuples cannot

15.

What is the purpose of the return statement in a function?

a)

A) To print the output of a function

b)

B) To terminate the function

c)

C) To send a value back to the caller

d)

D) To define a variable

16.

How do you call a function in Python?

a)

A) By using the function's name followed by parentheses ()

b)

B) By using the function keyword

c)

C) By using the call() method

d)

D) By using the run() function

17.

Can you modify the elements of a tuple after it is created?

a)

A) Yes

b)

B) No

c)

C) Only if it has a single element

d)

D) Only if it is empty

18.

How do you create an empty tuple in Python?

a)

A) empty_tuple = []

b)

B) empty_tuple = {}

c)

C) empty_tuple = ()

d)

D) empty_tuple = set()

19.

 What is the purpose of keys in a dictionary?

a)

A) To define the data type

b)

B) To represent the index of a value

c)

C) To uniquely identify and access values

d)

D) To sort the dictionary

20.

How do you remove a key-value pair from a dictionary in Python?

a)

A) remove()

b)

B) delete()

c)

C) pop()

d)

D) discard()

21.

What is the purpose of the try statement in Python?

a)

A) To raise an exception

b)

B) To handle exceptions

c)

C) To define a function

d)

D) To terminate the program

22.

Which of the following is NOT a built-in exception in Python?

a)

A) ValueError

b)

B) TypeError

c)

C) MyException

d)

D) IndexError

23.

What is the purpose of code testing and debugging in Python?

a)

A) To write code faster

b)

B) To catch and fix errors in your code

c)

C) To improve code readability

24.

Which tool is commonly used for code testing and debugging in Python?

a)

A) IDLE

b)

B) A code editor

c)

C) Pytest

d)

D) All of the above

25.

What is the purpose of a variable in Python?

a)

A) To perform complex mathematical operations

b)

B) To store and manage data

c)

C) To create loops

d)

D) To display messages to the user

26.

What data type is used to store whole numbers in Python?

a)

A) Float

b)

B) String

c)

C) Integer

d)

D) Boolean

27.

Which of the following is not a basic arithmetic operator in Python?

a)

A) -

b)

B) *

c)

C)$

d)

D) %

28.

What are the two Boolean values in Python?

a)

A) Yes and No

b)

B) True and False

c)

C) On and Off

d)

D) Positive and Negative Correct

29.

In a conditional statement, what keyword is used to execute a block of code if a condition is met?

a)

A) while

b)

B) for

c)

C) then

d)

D) if

30.

Which loop in Python is used for iterating over a sequence (e.g., a list)?

a)

A) while loop

b)

B) do-while loop

c)

C) for loop

d)

D) if loop Correct

31.

What is the primary purpose of a Python list?

a)

A) To store key-value pairs

b)

B) To group related data

c)

C) To perform mathematical calculations

d)

D) To handle exceptions Correct

32.

Which logical operator returns True if both operands are True in Python?

a)

A) and

b)

B) or

c)

C) not

d)

D) xor

33.

What is a primary use of functions in Python?

a)

A) To create conditional statements

b)

B) To store user input

c)

C) To encapsulate and reuse code

d)

D) To access dictionary elements

34.

What are exceptions used for in Python?

a)

A) To enhance program performance

b)

B) To handle errors and exceptional situations

c)

C) To create dictionaries

d)

D) To create loops Correct

35.

Which statement is used to catch and handle exceptions in Python?

a)

A) if-else

b)

B) try-except

c)

C) while

d)

D) for

36.
  1. How can you read data from a file in Python?

a)

A) Using the read() function

b)

B) Using the write() function

c)

C) Using the open() function

d)

D) Using the input() function Correct

37.

What is the correct way to declare a variable in Python?

a)

A) variable x = 5

b)

B) x = 5

c)

C) set x = 5

d)

D) 5 = x

38.

What function is used to display output to the console in Python?

a)

A) print()

b)

B) display()

c)

C) show()

d)

D) output()

39.

Which of the following is a comparison operator in Python?

a)

A) &

b)

B) |

c)

C) ==

d)

D) !

40.

In a Python if statement, what is executed if the condition is not met?

a)

A) The elif block

b)

B) The else block

c)

C) The for loop

d)

D) The try block

41.

Which loop in Python repeats a block of code until a condition is met?

a)

A) for loop

b)

B) while loop

c)

C) if loop

d)

D) try loop

42.

What logical operator returns True if at least one operand is True in Python?

a)

A) and

b)

B) or

c)

C) not

d)

D) xor

43.

What is the correct syntax for defining a Python function?

a)

A) function my_function():

b)

B) def my_function():

c)

C) my_function(): def

d)

D) define my_function():

44.

What is the primary purpose of a Python dictionary?

a)

A) To store a sequence of items

b)

B) To calculate mathematical expressions

c)

C) To store key-value pairs

d)

D) To create conditional statements

45.

What is the key difference between a tuple and a list in Python?

a)

A) Tuples are immutable, lists are not

b)

B) Lists are ordered, tuples are not

c)

C) Lists can store multiple data types, tuples cannot

d)

D) Tuples are immutable, lists are not

46.

Which of the following is a bitwise operator in Python?

a)

A) &

b)

B) or

c)

C) not

d)

D) and

47.

What does the try block in Python exception handling do?

a)

A) Executes the code that may raise an exception

b)

B) Skips the execution of the code

c)

C) Terminates the program

d)

D) Displays an error message

48.

Which operator is used to access a specific value in a dictionary in Python?

a)

A) []

b)

B) ()

c)

C) {}

d)

D) <>

49.

How can you write data to a file in Python?

a)

A) Using the write() function

b)

B) Using the read() function

c)

C) Using the input() function

d)

D) Using the open() function

50.

What is the result of the expression 10 / 2 in Python?

a)

A) 5.0

b)

B) 5

c)

C) 10

d)

D) 0.5

51.

Which of the following is a valid string in Python?

a)

A) "Hello World"

b)

B) Hello World

c)

C) Hello_World

d)

D) HelloWorld

52.

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

a)

A) To calculate logarithms

b)

B) To find the length of a string or sequence

c)

C) To perform mathematical operations

d)

D) To round floating-point numbers

53.

Which data type is used to store decimal numbers in Python?

a)

A) String

b)

B) Float

c)

C) Integer

d)

D) List

54.

What is the output of print("Hello" + " " + "World") in Python?

a)

A) Hello World

b)

B) HelloWorld

c)

C) Hello_World

d)

D) Hello+World

55.

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

a)

A) To round floating-point numbers

b)

B) To convert a string to an integer

c)

C) To calculate logarithms

d)

D) To find the absolute value

56.

Which of the following is a valid Python variable name?

a)

A) 2var

b)

B) my_variable

c)

C) variable-name

d)

D) #var

57.

What does the % operator do in Python?

a)

A) Exponentiation

b)

B) Floor division

c)

C) Modulo (remainder)

d)

D) Multiplication

58.

Which of the following is a boolean operator in Python?

a)

A) and

b)

B) or

c)

C) not

d)

D) All of the above

59.

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

a)

A) To get user input

b)

B) To perform mathematical operations

c)

C) To round floating-point numbers

d)

D) To display output to the console

60.

Which of the following is a valid Python data type for whole numbers?

a)

A) Float

b)

B) String

c)

C) Integer

d)

D) Boolean

61.

What is the correct way to declare a variable in Python?

a)

A) variable x = 5

b)

B) x = 5

c)

C) set x = 5

d)

D) 5 = x

62.

How can you add an element to the end of a list in Python?

a)

A) list.append(element)

b)

B) list.insert(0, element)

c)

C) list.add(element)

d)

D) list.extend(element)

63.

What is the correct way to access the third element in a list named my_list?

a)

A) my_list(2)

b)

B) my_list[2]

c)

C) my_list{2}

d)

D) my_list.third()

64.

Which of the following is a valid way to remove an element from a list in Python?

a)

A) list.remove(element)

b)

B) list.delete(element)

c)

C) list.pop(element)

d)

D) list.discard(element)

65.

What is the purpose of the range() function in a for loop?

a)

A) To generate a sequence of numbers

b)

B) To perform mathematical calculations

c)

C) To create conditional statements

d)

D) To handle exceptions

66.

What is the purpose of the “in” operator in Python?

a)

A) To perform mathematical calculations

b)

B) To check membership in a list or sequence

c)

C) To create conditional statements

d)

D) To handle exceptions

67.

How can you iterate over both the index and element of a list in a for loop?

a)

A) for index in my_list:

b)

B) for element in my_list:

c)

C) for index, element in enumerate(my_list):

d)

D) for element, index in my_list:

68.

How can you create a shallow copy of a list in Python?

a)

A) new_list = list.copy()

b)

B) new_list = list.clone()

c)

C) new_list = list[:]

d)

D) new_list = copy(list)

69.

What is the purpose of the break statement in a loop?

a)

A) To exit the loop prematurely

b)

B) To skip the current iteration and continue with the next

c)

C) To create an infinite loop

d)

D) To restart the loop from the beginning

70.

What is the key difference between the and and or logical operators?

a)

A) and returns True if both operands are True; or returns True if at least one operand is True.

b)

B) and returns True if at least one operand is True; or returns True if both operands are True.

c)

C) and is used for bitwise operations; or is used for logical operations.

d)

D) and is a unary operator; or is a binary operator.

71.

Which bitwise operator is used for flipping the bits of a binary number in Python?

a)

A) &

b)

B) |

c)

C) ~

d)

D) ^

72.

What is the purpose of the else clause in a for loop?

a)

A) To create an infinite loop

b)

B) To execute a block of code if the loop is interrupted by a break statement

c)

C) To execute a block of code if the loop completes without interruption

d)

D) To skip the current iteration and continue with the next

73.

How can you concatenate two lists in Python?

a)

A) list1.add(list2)

b)

B) list1.extend(list2)

c)

C) list1 + list2

d)

D) concat(list1, list2)

74.

What is the result of the expression 5 & 3 in Python?

a)

A) 7

b)

B) 1

c)

C) 3

d)

D) 0