wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Final Assessment

Total questions: 51

Worksheet time: 45mins

Name
Class
Date
1.

Which of the following is a valid variable name in Python?

a)

1variable

b)

variable-name

c)

variable_name

d)

variable name

2.

What will be the output of `print(5 + 3 * 2)` in Python?

a)

16

b)

11

c)

13

d)

23

3.

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

a)

int

b)

list

c)

str

d)

float

4.

How do you take user input in Python?

a)

input()

b)

scan()

c)

read()

d)

get()

5.

What will be the result of `3 ** 2` in Python?

a)

6

b)

9

c)

5

d)

8

6.

How do you denote a comment in Python?

a)

/* comment */

b)

# comment

c)

// comment

d)
7.

Which operator is used to check equality in Python?

a)

=

b)

==

c)

!=

d)

>

8.

What is the output of `print("Hello".format("World"))`?

a)

HelloWorld

b)

Hello World

c)

World

d)

Hello

9.

Which keyword is used to start a conditional statement in Python?

a)

switch

b)

if

c)

when

d)

case

10.

How do you create a list in Python?

a)

[]

b)

{}

c)

()

d)

<>

11.

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

a)

[1, 2, 3, 4, 5]

b)

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

c)

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

d)

[4, 5, 1, 2, 3]

12.

What method adds an element to the end of a list?

a)

append()

b)

add()

c)

insert()

d)

extend()

13.

How do you define a function in Python?

a)

function myFunc()

b)

def myFunc()

c)

func myFunc()

d)

define myFunc()

14.

Which of the following is used to return a value from a function?

a)

return

b)

yield

c)

result

d)

output

15.

What is the output of `print(len("Python"))`?

a)

5

b)

6

c)

7

d)

8

16.

Which Python keyword is used to create a class?

a)

class

b)

create

c)

def

d)

object

17.

What is inheritance in Python?

a)

Creating new classes from existing ones

b)

A method within a class

c)

A way to handle exceptions

d)

A type of loop

18.

How do you open a file for reading in Python?

a)

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

b)

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

c)

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

d)

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

19.

How do you read the entire content of a file in Python?

a)

file.read()

b)

file.readlines()

c)

file.get()

d)

file.scan()

20.

Which module would you use for numerical operations in Python?

a)

scipy

b)

numpy

c)

matplotlib

d)

sympy

21.

How do you import a module in Python?

a)

include module_name

b)

import module_name

c)

use module_name

d)

require module_name

22.

Which method is used to find the length of a list?

a)

length()

b)

size()

c)

count()

d)

len()

23.

What will be the output of the following code? `print("5" * 2)`

a)

10

b)

"55"

c)

52

d)

55

24.

What is the purpose of the `self` keyword in Python classes?

a)

To refer to the instance of the class

b)

To refer to a global variable

c)

To refer to a static method

d)

To create a new instance

25.

How can you check if a number is even in Python?

a)

num % 2 == 0

b)

num % 2 != 0

c)

num // 2 == 0

d)

num & 1 == 0

26.

What will be the output of `print(type(5.0))`?

a)

int

b)

str

c)

float

d)

list

27.

How do you handle exceptions in Python?

a)

try...except

b)

catch...finally

c)

handle...error

d)

error...catch

28.

What is a tuple in Python?

a)

A mutable sequence

b)

An immutable sequence

c)

A dynamic array

d)

A dictionary

29.

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

a)

remove()

b)

pop()

c)

delete()

d)

discard()

30.

How do you define a class method in Python?

a)

def method_name(self):

b)

@classmethod

c)

def method_name(cls):

d)

@method

31.

What is the result of `print("Python"[:3])`?

a)

Python

b)

Pyt

c)

hon

32.

Which loop is used when the number of iterations is known?

a)

while

b)

for

c)

repeat

d)

do-while

33.

How do you convert a string to an integer in Python?

a)

int()

b)

str()

c)

float()

d)

convert()

34.

What is the default return value of a function that does not have a return statement?

a)

None

b)

0

c)

False

d)

""

35.

Which operator is used for floor division in Python?

a)

/

b)

//

c)

%

d)

**

36.

What is the purpose of the `__init__` method in Python classes?

a)

To initialize class variables

b)

To initialize instance variables

c)

To destroy instance variables

d)

To initialize the class

37.

What will be the output of the following code?

x = [1, 2, 3]

x.append([4, 5])

print(x)

a)

[1, 2, 3, 4, 5]

b)

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

c)

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

d)

[4, 5, 1, 2, 3]

38.

How do you define a default argument in a function?

a)

def func(arg=default_value):

b)

def func(arg, default_value):

c)

def func(arg, default_value=default_value):

d)

def func(default_value=default_value):

39.

Which method is used to sort a list in ascending order?

a)

sort()

b)

order()

c)

arrange()

d)

arrange_ascending()

40.

What will be the output of the following code?

4 lines
41.

Which of the following statements is true about Python functions?

a)

Functions can only return one value.

b)

Functions can return multiple values.

c)

Functions cannot return any value.

d)

Functions are only used for mathematical calculations.

42.

What will be the output of the following code?

(a)  

43.

What will be the output of the following code?

(a)  

44.

You need to handle user input and perform different actions based on the input. You want to execute a specific block of code depending on whether the user enters "start", "stop", or "exit". How should you implement this in Python?

a)

Use a series of if-elif-else statements to check the user input.

b)

Use nested if statements for each condition.

c)

Use a single if statement with multiple conditions connected by or.

d)

Use a switch statement to handle different cases.

45.

You need to merge two dictionaries in Python. Which method would you use if you are using Python 3.9 or later?

a)

dict.update()

b)

dict.merge()

c)

{**dict1, **dict2}

d)

dict.combine()

46.

You want to handle multiple exceptions in a single try block. How should you do this?

a)

Use multiple try blocks for each exception.

b)

Use a single except block with multiple exception types separated by commas.

c)

Use a single except block for each exception type.

d)

Handle each exception using a separate finally block.

47.

You have a list of integers and you want to get the maximum value from it. The function you would use is (a)   .

48.

Scenario: To open a file for writing in Python, you should use the mode (a)   .

49.

Scenario: To remove leading and trailing whitespace from a string, you use the (a)   method.

50.

What will be the output of the following code?

a)

6

b)

5

c)

UnboundLocalError: local variable 'x' referenced before assignment

d)

None

51.

Write a Python function called unique_characters that takes a string as input and returns True if all characters in the string are unique (i.e., no character appears more than once), and False otherwise.

requirements:

  • The function should be case-sensitive (e.g., 'A' and 'a' are considered different characters).

  • You cannot use any built-in Python collections like sets or dictionaries for this problem.

Example:

print(unique_characters("hello")) # Output: False

print(unique_characters("world")) # Output: True

print(unique_characters("Python")) # Output: True

print(unique_characters("aAbBcC")) # Output: False

4 lines