wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

Which of the following is a valid Python variable name?

a)

my_var

b)

2ndVar

c)

my-var

d)

my var

2.

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

a)

merge()

b)

combine()

c)

split()

d)

join()

3.

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

a)

my_list[0]

b)

my_list[-1]

c)

my_list[last]

d)

my_list[1:]

4.

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

a)

If the string is uppercase.

b)

If the string contains whitespace.

c)

If the string starts with a specified substring.

d)

If the string is alphanumeric.

5.

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

a)

 True

b)

False

c)

Error

d)

None

6.

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

a)

dict.getKey()

b)

dict[key]

c)

dict.value(key)

d)

dict(key)

7.

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

a)

sorted()

b)

sort()

c)

order()

d)

arrange()

8.

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

a)

None

b)

 Error

c)

True

d)

False

9.

Which of the following is NOT a valid Python loop?

a)

while

b)

for

c)

do-while

d)

nested for

10.

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

a)

Error

b)

False

c)

True

d)

None

11.

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

a)

int()

b)

str()

c)

string()

d)

convert()

12.

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

a)

count()

b)

find()

c)

index()

d)

repeat()

13.

What does the pass keyword do in Python?

a)

Raises an exception.

b)

Ends the execution of a function.

c)

Skips the next iteration of a loop.

d)

Acts as a placeholder and does nothing.

14.

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

a)

<class 'int'>

b)

<class 'float'>

c)

<class 'complex'>

d)

<class 'decimal'>

15.

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

a)

pop()

b)

remove()

c)

del

d)

clear()