wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Python Quiz

Total questions: 16

Worksheet time: 8mins

Name
Class
Date
1.

What would be printed by the command

print('12-5')

a)

12-5

b)

'12-5'

c)

7

d)

'7'

2.

Which of the operators do we use if we want at least one condition to be true?

a)

and

b)

or

c)

else

d)

not

3.
What will the output be from the following code?
print(Hello world!)
a)
Hello world!
b)
SyntaxError
c)
Hello world
d)
print(Hello world!)
4.

What will be the output of the following statement?

type('5')

a)

str

b)

int

c)

float

d)

Boolean

5.

Which one is NOT a legal variable name?

a)

my_var

b)

myvar

c)

_myvar

d)

my-var

6.

How do you create a variable with the numeric value 5?

a)

Both are correct

b)

x=5

c)

x=int(5)

7.

a = "Good Morning!"

print(len(a))

a)

13

b)

12

c)

11

d)

14

8.

What is the purpose of the input() function in Python?

a)

To take input from the user

b)

To convert an object into a string

c)

To print a message on the screen

d)

To add a string at the end of the output

9.

What is the output of print(5 + 2) in Python?

a)

A. 52

b)

B. 7

c)

C. "5 + 2"

d)

D. Error

10.

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

a)

A) int x = 10

b)

B) x := 10

c)

C) var x = 10

d)

D) x = 10

11.

Which of the following is the correct way to start a for loop in Python?

a)

A) for(int i=0; i<5; i++)

b)

B) for i in range(5):

c)

C) for(i=0; i<5; i++):

d)

D) for i < 5:

12.

How do you create a list in Python?

a)

A) list = list(1, 2, 3, 4, 5)

b)

B) list = [1, 2, 3, 4, 5]

c)

C) list = (1, 2, 3, 4, 5)

d)

D) list = {1, 2, 3, 4, 5}

13.

Which of the following is used to define a block of code in Python?

a)

A) Curly braces { }

b)

B) Keywords begin and end

c)

C) Indentation

d)

D) Parentheses ( )

14.

What will be the output of the following code?

x = ["apple", "banana", "cherry"]

x.append("orange")

print(x)

a)

x = ["apple", "banana", "cherry"]

x.append("orange")

print(x)

b)

B) ["orange", "apple", "banana", "cherry"]

c)

C) ["apple", "orange", "banana", "cherry"]

d)

C) ["apple", "orange", "banana", "cherry"]

15.

Which method is used to remove the last item from a list?

a)

A) pop()

b)

B) push()

c)

C) delete()

d)

D) remove()

16.

How do you create a variable with the floating number 2.8?

a)

x=2.8

b)

x=float(2.8)

c)

both are correct