wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Scope of Variables in Python

Total questions: 15

Worksheet time: 15mins

Name
Class
Date
1.

What is the output of the following python program?

a)

Error

b)

12

c)

15

d)

1512

2.

What is the output of the following python code?

a)

Error

b)

100

c)

99

d)

101

3.

What is the output of the following python code?

a)

13

b)

10

c)

2

d)

5

4.

What is the output of the following python code?

a)

error

b)

hello

c)

16

d)

16

hello

5.

What is the output of the following python code?

a)

Error

b)

12 4

c)

4 12

d)

4 15

6.

What is the output of the following python code?

a)

1 2 3 4

b)

5 10 15 20

c)

10 20 30 40

d)

5 10 15 40

7.

What is the output of the following python code?

a)

outer

error

b)

inner

outer

c)

outer

inner

d)

error

8.

What is the output of the following python code?

a)

Error

b)

7

c)

8

d)

15

9.

What is the output of the following python code?

a)

I Love Paris in the summer

b)

error

c)

I Love Paris in the summer

I Love Paris in the summer

10.

What is the output of the below python code?

a)

I am looking for a course in Paris!

b)

Only in spring, but London is great as well!

Only in spring, but London is great as well!

I am looking for a course in Paris!

c)

I am looking for a course in Paris!

Only in spring, but London is great as well!

Only in spring, but London is great as well!

d)

Only in spring, but London is great as well!

I am looking for a course in Paris!

Only in spring, but London is great as well!

11.

What is the output of the following python code?

a)

42 17 4 17

42 15 3 4

b)

1 15 3 4

c)

17 4

d)

42 33 17 100

12.

What is the output of the following python code?

x=100

def f1():

global x

x=90

def f2():

global x

x=80

print(x)

a)

100

b)

90

c)

80

d)

error

13.

Read the following Python code carefully and point out the global variables?

y, z = 1, 2

def f():

global x

x = y+z

a)

x

b)

y and z

c)

x, y and z

d)

Neither x, nor y, nor z

14.

How are variable length arguments specified in the function heading?

a)

one star followed by a valid identifier

b)

one underscore followed by a valid identifier

c)

two stars followed by a valid identifier

d)

two underscores followed by a valid identifier

15.

What is the output of this python code?

def foo(x):

x[0] = ['def']

x[1] = ['abc']

return id(x)

q = ['abc', 'def']

print(id(q) == foo(q))

a)

Error

b)

True

c)

False

d)

None