wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python final questions part 2

Total questions: 62

Worksheet time: 31mins

Name
Class
Date
1.

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]

2.

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

3.

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



a)

False

b)

True

c)

None

d)

Error

4.

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)

5.

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

a)

pop()

b)

remove()

c)

delete()

d)

discard()

6.

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.

7.

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

a)

type()

b)

typeof()

c)

object_type()

d)

classof()

8.

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

a)

False

b)

True

c)

None

d)

Error

9.

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.

10.

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]

11.

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



a)

*

b)

+

c)

&

d)

!

12.

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.

13.

Which function is used to round a number in Python?

a)

round()

b)

ceil()

c)

floor()

d)

approx()

14.

How do you create an empty set in Python?



a)

set()

b)

{}

c)

[]

d)

()

15.

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

a)

1

b)

1.3333

c)

0.75

d)

Error

16.

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

a)

0


b)

-1

c)

None

d)

Error

17.

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



a)

{'key': 'value'}

b)

{key = value}

c)

['key', 'value']

d)

(key, value)

18.

Which Python keyword is used to create a generator?



a)

yield

b)

return

c)

generate

d)

create

19.

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.

20.

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

a)

in

b)

of

c)

has

d)

contains

21.

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

a)

python

b)

PYTHON

c)

Python

d)

None

22.

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

a)

replace()

b)

change()

c)

update()

d)

switch()

23.

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]

24.

Which method removes all items from a list?


a)

clear()

b)

delete()

c)

remove_all()

d)

empty()

25.

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

a)

add()

b)

insert()

c)

append()

d)

extend()

26.

Which function can convert a list into a set?



a)

set()

b)

convert_set()

c)

make_set()

d)

list_to_set()

27.

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.

28.

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

a)

<class 'list'>

b)

<class 'tuple'>

c)

<class 'set'>

d)

<class 'dict'>

29.

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

a)

items()

b)

keys()

c)

values()

d)

iterate()

30.

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

a)

2.5

b)

2

c)

Error

d)

3

31.

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.

32.

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.

33.

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

a)

startswith()

b)

endswith()

c)

checkprefix()

d)

eginwith()

34.

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

a)

55

b)

10

c)

Error

d)

5 + 5

35.

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

36.

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.

37.

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



a)

lambda

b)

function

c)

def

d)

anonymous

38.

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



a)

2.0

b)

2

c)

4

d)

16

39.

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

a)

a)

keys()

b)

values()

c)

items()

d)

get_keys()

40.

Which data type is unordered in Python?

a)

set

b)

list

c)

tuple

d)

string

41.

What is the default value of a boolean in Python?

a)

False

b)

None

c)

True

d)

0

42.

What will print(bool(0)) output?



a)

False

b)

True

c)

Error

d)

0

43.

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

44.

Which Python keyword is used to exit a function?

a)

return

b)

break

c)

exit

d)

stop

45.

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



a)

\n

b)

\t

c)

\\

d)

//

46.

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



a)

3

b)

3.33

c)

10.0

d)

Error

47.

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

a)

<class 'list'>

b)

<class 'tuple'>

c)

<class 'dict'>

d)

<class 'set'>

48.

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

a)

str()

b)

int()

c)

string()

d)

float()

49.

What is the default starting index for Python lists?

a)

0

b)

1

c)

-1

d)

None

50.

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

a)

pop(index)

b)

remove(index)

c)

delete(index)

d)

discard(index)

51.

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.

52.

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

53.

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



a)

Hello

b)

HELLO

c)

hello

d)

None

54.

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



a)

True

b)

False

c)

None

d)

Error

55.

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.

56.

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

a)

len(list)

b)

size(list)

c)

count(list)

d)

length(list)

57.

Which of the following is a valid Python variable name?

a)

my_var

b)

2ndVar

c)

my-var

d)

my var

58.

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

a)

join()

b)

split()

c)

combine()

d)

merge()

59.

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:]

60.

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.

61.

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



a)

True

b)

False

c)

Error

d)

None

62.

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



a)

dict[key]

b)

dict.getKey()

c)

dict.value(key)

d)

dict(key)