wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python_Variables

Total questions: 9

Worksheet time: 5mins

Name
Class
Date
1.

In Python, a variable must be declared before it is assigned a value:

a)

False

b)

True

c)

None

2.

Which of the following statements assigns the value 100 to the variable x in Python:

a)

x := 100

b)

x = 100

c)

x << 100

d)

let x = 100

e)

x <- 100

3.

In Python, a variable may be assigned a value of one type, and then later assigned a value of a different type:

a)

False

b)

True

c)

None

4.

Consider the following sequence of statements:


n = 300

m = n


Following execution of these statements, Python has created how many objects and how many references?

a)

Two objects, two references

b)

One objects, two references

c)

One objects, one references

d)

Two objects, one references

5.

What Python built-in function returns the unique number assigned to an object:

a)

ref( )

b)

identity( )

c)

id( )

d)

refnum( )

6.

Which of the following are valid Python variable names:

a)

router66

b)

ver1.3

c)

Age

d)

return

e)

home_address

7.

You are reading Python code, and these statements appear scattered in different locations throughout the code:


employeenumber = 4398

.

.

.

EmployeeNumber = 4398

.

.

.

employeeNumber = 4398

a)

These statements refer to different variables.

b)

These statements refer to the same variable.

8.

Which of the following styles does PEP8 recommend for multi-word variable names:

a)

DistanceToNearestTown (Pascal Case)

b)

distanceToNearestTown (Camel Case)

c)

distance_to_nearest_town (Snake Case)

d)

None

9.

Which of the following are Python reserved words (keywords):

a)

None

b)

default

c)

class

d)

goto

e)

and