wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python

Total questions: 35

Worksheet time: 22mins

Name
Class
Date
1.

How do we define a variable in Python?

a)

variable : 10

b)

variable 10

c)

variable == 10

d)

variable = 10

2.

Which of the following is a correct way to check if two variables are equal in Python?

a)

var1 = var2

b)

var1 == var2

c)

var1 === var2

d)

var1 = = var2

3.

What is the correct way to declare a list in Python?

a)

list = [1, 2, 3]

b)

list : [1, 2, 3]

c)

list (1, 2, 3)

d)

list == [1, 2, 3]

4.

What is the correct way to add an element to the end of a list in Python?

a)

list.add(4)

b)

list.append(4)

c)

list.insert(4)

d)

list.extend(4)

5.

What is the correct way to remove an element from a list in Python?

a)

list.remove(3)

b)

list.delete(3)

c)

list.pop(3)

d)

list.discard(3)

6.

How to initiate an empty list to variable "myList" in python

(a)  

7.

How do you define a for loop in that iterates over the numbers from 0 to 10?

(a)  

8.

What is the correct way to iterate over a list in Python?

a)

for i in list:

b)

for i in range(len(list)):

c)

for i in range(list):

d)

for i in list(range):

9.

What is the correct way to get the length of a list in Python?

a)

len(list)

b)

list.length()

c)

list.size()

d)

list.count()

10.

How to access an element at index i in Python list?

a)
list[i]
b)
list.get(i)
c)
list(i)
d)
list.index(i)
11.

How do we check if boolean variables var1 and var2 are both in Python?

a)
var1 or var2
b)
var1 | var2
c)
var1 and var2
d)
var1 & var2
12.

How do we define an if statement in Python?

a)
An if statement in Python is defined using the keyword 'else' followed by a condition.
b)
An if statement in Python is defined using the keyword 'for' followed by a condition.
c)
An if statement in Python is defined using the keyword 'if' followed by a condition.
d)
An if statement in Python is defined using the keyword 'switch' followed by a condition.
13.

What is the correct way to insert an element at a specific index in a Python list?

a)

list.add(index, element)

b)

list.insert(index, element)

c)

list.place(index, element)

d)

list.update(index, element)

14.

What is the correct way to convert a string to uppercase in Python?

a)

str.upper()

b)

str.toUpper()

c)

str.convertUpper()

d)

str.caseUpper()

15.

What will be the output of the following code?

myList = []

for i in range(2,8):

myList.append(i)

print(myList)

a)
[2, 3, 4, 5, 6, 8]
b)
[2, 3, 4, 5, 6, 7]
c)
[3, 4, 5, 6, 7, 8]
d)
[1, 2, 3, 4, 5, 6]
16.
What is the word (command) used to display numbers and text on the screen?
a)
print
b)
input
c)
output
d)
command
17.
What will be the output?
name = 'Dave'
print (name)
a)
Dave
b)
'Dave'
c)
name
d)
(name)
18.
Which of these would work as a piece of code?
a)
IF answer == "Yes":
b)
if answer == "Yes"
c)
if answer == "Yes":
d)
if answer = "yes":
19.
What will the output be from the following code?
print(3+4)
a)
3+4
b)
7
c)
SyntaxError
d)
print(3+4)
20.
What will the output be from the following code?
print("3+4")
a)
7
b)
3+4
c)
34
d)
SyntaxError
21.
Data type that can only be true or false
a)
int
b)
string
c)
bool
d)
float
22.

Which of these is a string?

a)

42

b)

True

c)

"This one!"

d)

No, this one

23.

numbers = [5, 14, 9, 17]

for number in numbers:

if number % 3 == 0:

print(number)


The output will be?

a)

17

b)

9

c)

14

9

17

d)

14

17

24.

numbers = [5, 14 ,9, 17]

for number in numbers:

if number >= 9:

print (number)


The output will be?

a)

17

b)

9

c)

14

9

17

d)

14

17

25.
How many times does the following program print the word ‘computer’:

word= "computer"  
for num in range(1,6):
 
    print(word)
a)
5
b)
6
c)
1
d)
0
26.

Which of the following for loops would print the following numbers?

3 5 7 9

a)

for i in range(3, 10, 2):

print(i)

b)

for i in range(3, 9, 2):

print(i)

c)

for i in range(9):

print(i)

d)

for i in range(3,9):

print(i)

27.

What would be the output of the following code:

for i in range(3):

print(5)

a)

0 1 2

b)

3 3 3 3 3

c)

5 5 5

d)

0 1 2 3 4

28.
Which statement will check to see if a is equal to b?
a)
if a == b
b)
if a = b:
c)
if a != b:
d)
if a == b:
29.

What is the correct way to check if a number is even in Python?

a)

number % 2 == 0

b)

number % 2 = 0

c)

number / 2 == 0

d)

number / 2 = 0

30.

What is the correct way to check if a variable is equal to a specific value in Python?

a)

var1 = var2

b)

var1 == var2

c)

var1 === var2

d)

var1 = = var2

31.

Which of the following is a boolean data type in Python?

a)

int

b)

string

c)

bool

d)

float

32.

What will be the output of the following code?

myList = [1, 2, 3]

for i in myList:

print(i * 2)

a)

1 2 3

b)

2 4 6

c)

3 6 9

d)

4 8 12

33.

How do we loop over a list in Python using the range function?

a)
for i in range(len(my_list)): print(my_list[i])
b)
for i in range(1, len(my_list)): print(my_list[i])
c)
for i in range(len(my_list) - 1): print(my_list[i])
d)

for i in range(my_list): print(my_list[i])

34.

How do we get a string input in Python?

a)
get_string()
b)
input()
c)
user_input()
d)
read_string()
35.

How do we get an integer as an input in Python?

a)

number = input()

b)

number = int(input())

c)

number = input(integer())

d)

number = input(int("Give me an integer"))