wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python variables and operators quiz

Total questions: 20

Worksheet time: 9mins

Name
Class
Date
1.

Which of the following is NOT a valid Python data type?

a)

float

b)

int

c)

str

d)

positive

2.

To test whether one number is greater than or equal to another, you would use the ​ (a)   conditional operator.

Choose from the below words
>=
<=
>
<
=
3.

Which of the following is a valid Python assignment statement?

a)

x = 3

b)

x := 3

c)

x == 3

d)

x <- 3

4.

What is the correct Python syntax to output the type of a variable?

a)

print(type(x))

b)

print(typeof(x))

c)

print(typeof x)

d)

print(type x)

5.

How do you insert COMMENTS in Python code?

a)

// this is a comment

b)

/* this is a comment */

c)

# this is a comment

d)

-- this is a comment

6.

Which of the following is NOT a Python keyword?

a)

for

b)

while

c)

loop

d)

if

7.

Which of the following will prompt a user for input and assign that input to a variable?

a)

x = input("Please enter your name: ")

b)

x = get(input)

c)

x = prompt("Enter your name: ")

d)

x = "Please enter your name: "

8.

How do you declare a variable in Python?

a)

var x = 10;

b)

int x = 10;

c)

x = 10

d)

declare x = 10;

9.

What is the output of the following Python code snippet?

print(type(5.0))

a)

<class 'int'>

b)

<class 'float'>

c)

<class 'str'>

d)

<class 'bool'>

10.

Which of the following is NOT a valid Python comparison operator?

a)

!=

b)

==

c)

<=

d)

=<

11.

What symbol is used at the end of an if, else, or elif statement to indicate the code that follows is part of a separate block of code that is only executed if the condition is met?

a)

:

b)

|

c)

@

d)

#

12.

You should ​ (a)   input to another data type if you don't want a string.

Choose from the below words
cast
swap
invert
flip
13.

Given the code x = 3 + 5.0, the value of x is ​ (a)  

Choose from the below words
8.0
8
3
5.0
14.

Given the code x = 3 + 5.0, what does print(type(x)) show?

a)

<class 'float'>

b)

<class 'int'>

c)

<class 'str'>

d)

<class 'bool'>

15.

Given the code

biff = ['foo', 'bar', 'bam']

print(type(biff))

what is the result?

a)

<class 'list'>

b)

<class 'str'>

c)

<class 'foo, bar, bam'>

d)

foo, bar, bam

16.

If I wanted to create a series of related values, I would use the ​ (a)   data type.

Choose from the below words
list
float
int
bool
17.

If I want to print formatted output in Python, I should use which built-in function?

a)
print()
b)
format()
c)
printf()
d)
println()
18.

Match the following

a)

The code prints a string

1.

print("Hello World")

b)

The code concatenates (adds) strings together and prints the result

2.

print("Hello" + " " + "World")

c)

The code prints a formatted string with the value of an integer variable

3.

print("I have {:d} cats".format(3))

19.

What is the output of the following Python code?

x = 5

y = 10

print(x + y)

a)

15

b)

510

c)

5 + 10

d)

None of the above

20.

What is the output of the following Python code snippet? print(5 // 2)

a)

2.5

b)

2

c)

3

d)

None of the above