Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Programming Quiz

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

Which of the following is a correct way to declare a variable in Python?

a)

var = 10

b)

10 = var

c)

var == 10

d)

10 var =

2.

What is the output of print(2 ** 3)?

a)

8

b)

6

c)

9

d)

7

3.

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

a)

len()

b)

length()

c)

size()

d)

count()

4.

How do you add an element x to a list my_list in Python?

a)

my_list.append(x)

b)

my_list.add(x)

c)

my_list.insert(x)

d)

my_list.addElement(x)

5.

What is the result of the expression 5 // 2?

a)

2.5

b)

3

c)

2

d)

2.0

6.

What will be the output of print("Hello" * 3)?

a)

HelloHelloHello

b)

Hello 3

c)

HelloHello 3

d)

3Hello

7.

Which function is used to take input from the user in Python?

a)

input()

b)

read()

c)

get()

d)

scan()

8.

How do you write a single-line comment in Python?

a)

/* This is a comment */

b)

// This is a comment

c)

# This is a comment

d)

-- This is a comment

9.

Which of the following is used to handle exceptions in Python?

a)

try-except

b)

if-else

c)

for-else

d)

do-while

10.

Which of the following is a valid string declaration in Python?

a)

str = "Hello"

b)

str = 'Hello"

c)

str = Hello

d)

str = """Hello"""

11.

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

a)
b)
c)
d)
12.

How can you check the type of a variable x in Python?

a)

type(x)

b)

typeof(x)

c)

check(x)

d)

var_type(x)

13.

Which of the following is the correct syntax to define a function in Python?

a)

def my_function()

b)

function my_function()

c)

define my_function()

d)

function = my_function()

14.

What does len() return when applied to a dictionary?

a)

The number of keys in the dictionary

b)

The number of values in the dictionary

c)

The number of key-value pairs in the dictionary

d)

It raises an error

15.

How can you remove an item from a dictionary by its key?

a)

del dict[key]

b)

dict.remove(key)

c)

dict.pop(key)

d)

Both a and c

16.

What will print(3 == 3) output?

a)

True

b)

False

c)

None

d)

Error

17.

What will be the result of print(5 != 5)?

a)

True

b)

False

c)

None

d)

Error

18.

How would you create a set in Python?

a)

set = {1, 2, 3}

b)

set = (1, 2, 3)

c)

set = [1, 2, 3]

d)

set =

19.

Which Python keyword is used to define a class?

a)

def

b)

class

c)

function

d)

object

20.

Which method is used to add an element to a set in Python?

a)

set.add()

b)

set.insert()

c)

set.append()

d)

set.appendElement()

21.

How do you iterate over a list my_list in Python?

a)

for i in my_list:

b)

for (i: my_list)

c)

for i from my_list:

d)

foreach i in my_list:

22.

How would you find the maximum number from a list numbers = [2, 3, 1, 7, 5]?

a)

max(numbers)

b)

maximum(numbers)

c)

find_max(numbers)

d)

numbers.max()

23.

Which function can be used to sort a list my_list in ascending order?

a)

sort()

b)

order()

c)

arrange()

d)

sortList()

24.

How do you check if a key exists in a dictionary my_dict?

a)

my_dict.contains(key)

b)

key in my_dict

c)

my_dict.exists(key)

d)

my_dict.key(key)

25.

What is the output of print("python"[2:5])?

a)

tho

b)

pyth

c)

thon

d)

t

26.

Which of the following operators is used for floor division in Python?

a)

/

b)

%

c)

//

d)

^

27.

Which of the following is used to return the remainder of a division?

a)

//

b)

/

c)

%

d)

divmod()

28.

How do you check the length of a string in Python?

a)

str.length()

b)

length(str)

c)

len(str)

d)

size(str)

29.

What is the result of print(4 + 2 * 3)?

a)

12

b)

10

c)

8

d)

6

30.

Which of the following will raise an error in Python?

a)

a = "hello"

b)

x = 3.5 + 2

c)

print(2 + "3")

d)

y = [1, 2, 3]