Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python Basics Quiz

Total questions: 30

Worksheet time: 32mins

Name
Class
Date
1.

What will be the output of the following code?

# This is a comment

#print("Hello, World!")

a)

This is a comment

b)

Hello, World!

c)

# This is a comment

Hello, World!

d)

No output

e)

Error

2.

Which of the following is the correct way to write a multiline comment in Python?

a)

/* This is a comment */

b)

// This is a comment

c)

# This is a comment

d)

"""This is a comment"""

3.

What is the data type of the user input in the code below?

x = input("Enter a number: ")

a)

int

b)

float

c)

str

d)

bool

4.

Which line correctly converts the input to an integer?

a)

x = str(input())

b)

x = float(input())

c)

x = int(input())

d)

x = input(int())

5.

What will be the result of the following code?

x = 5 y = "3" print(x + int(y))

a)

8

b)

53

c)

Error

d)

5 + "3"

6.

Which of the following is a valid variable?

a)

2name = "John"

b)

full-name = "John"

c)

running_total = 123

d)

my class = 123

7.

Complete the code to print: My name is Ben and I am 13 years old.?

name = "Ben"

age = 13

print( (a)   )

8.

What is the output?

x = 7

if x > 10:

print("High")

elif x > 5:

print("Medium")

else:

print("Low")

a)

Big

b)

Medium

c)

Small

d)

Error

9.

How many times will the following loop run?

for i in range(3, 8):

print(i)

a)

5

b)

6

c)

7

d)

Infinite

10.

What will this code output?

x = 0

while x < 3:

print("Boo!")

x += 1

4 lines
11.

What will this code output?

x = (6/3)**2

print(x > 2 and x < 6)

(a)  

12.

What is the result of " Hello ".strip()?

a)

" hello "

b)

"Hello"

c)

"HELLO"

d)

" HELLO "

13.

Fill in the blank to print dave:

my_name = "Dave"

print (my_name. (a)   () )

14.

What does the code return:

word = "Exam - day"

word[2:6] return?

(a)  

15.

What is the output of

word = "computer"

word[-1:0:-1]?

a)

"retupmo"

b)

"computer"

c)

Error

d)

"com"

16.

Which expression will return True?

a)

"cat" in "caterpillar"

b)

"dog" not in "hotdog"

c)

"a" in "bcdef"

d)

"b" in "pizza"

17.

What is the result of 3 % 2?

a)
0
b)
2
c)
1
d)

This operator is not used in Python

18.

Which operator returns True only if both conditions are true?

a)

or

b)

not

c)

and

d)

None of the above

19.

What is the output?

mylist = [1, 2, 3, 9, "abc"]

print(mylist[2])

(a)  

20.

What will this code print?

mylist = [0, 2, 3]

mylist.append(1)

print(mylist)

a)
[0, 2, 3]
b)
[1, 0, 2, 3]
c)
[0, 2, 3, 1]
d)
[0, 1, 2, 3]
21.

What does mylist.clear() do?

a)

Deletes the last element

b)

Removes duplicates

c)

Empties the list

d)

Deletes the list

22.

Fill in the blank:

fruits = ["apple", "banana", "apple", "grape", "kiwi", "red apple", "green apple"]

fruits.count("apple") is going to be: (a)  

23.

Fill in the blank:

color["red", "blue", "green"]

print(color.index("blue"))

a)

Error

b)

True

c)
0
d)
1
e)

False

24.

Which list method removes an element by index?

a)

remove()

b)

delete()

c)

pop()

d)

cut()

25.

What will be the output?

colors = ["red", "blue"]

colors.insert(1, "green")

colors.sort()

colors.pop(1)

print(colors)

(a)  

26.

Which method removes an item by value?

a)

pop()

b)

remove()

c)

del()

d)

erase()

27.

What will be printed?

nums = [1, 2, 3]

nums.insert(1, 4)

nums.clear()

nums.pop(1)

print(nums)

a)

[1, 2, 4]

b)

[ ]

c)

[2, 4, 1]

d)

Error

e)

[1,2,3,4]

28.

What is the output if the user types "Python"?

a)

Welcome

b)

Try again!

c)

Error

d)

Enter your password

29.

What is the output of the code?

(a)  

30.

Fill in the blanks to complete the program so it prints only the even numbers between 1 and 10 (inclusive).

(a)