wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python final questions part 1

Total questions: 62

Worksheet time: 31mins

Name
Class
Date
1.

What is the primary purpose of a variable in Python?



a)

a) To store data values.

b)

b) To execute Python code.

c)

c) To display output on the screen.

d)

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.

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.

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():

28.

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.

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.

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

a)

sort()

b)

sorted()

c)

order()

d)

arrange()

55.

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



a)

False

b)

True

c)

Error

d)

None

56.

Which of the following is NOT a valid Python loop?

a)

do-while

b)

while

c)

for

d)

nested for

57.

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

a)

True

b)

False

c)

None

d)

Error

58.

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



a)

str()

b)

int()

c)

convert()

d)

string()

59.

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

a)

count()

b)

find()

c)

index()

d)

repeat()

60.

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.

61.

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

a)

<class 'float'>

b)

<class 'int'>

c)

<class 'complex'>

d)

<class 'decimal'>

62.

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

a)

pop()

b)

remove()

c)

del

d)

clear()