wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

ByteTheSnake

Total questions: 20

Worksheet time: 20mins

Name
Class
Date
1.

What is the output of print(2 == 2.0 is True)?

a)

 True

b)

False

c)

Error

d)

 None

2.

What does slots do in Python?

a)

Limits instance attributes

b)

Defines private variables

c)

Increases execution speed

d)

Both A and C

3.

What is the output of print(5 and 0 or 3)?

a)

0

b)

3

c)

5

d)

Error

4.

print({True: 'yes', 1: 'no', 1.0: 'maybe'})

a)

{True: 'yes', 1: 'no', 1.0: 'maybe'}

b)

{True: 'maybe'}

c)

 {True: 'yes'}

d)

{True: 'maybe'}

5.

What will print(hash((1, 2, 3))) return?

a)

A unique integer

b)

A string

c)

An error

d)

None

6.

What will be the output of print(0.1 + 0.2 == 0.3)?

a)

True

b)

False

c)

Error

d)

None

7.

What is the output of bool(set())?

a)

True

b)

False

c)

Error

d)

none

8.

What does islice() from itertools do?

a)

Slices an iterable without converting it to a list

b)

Works like list[start:stop]

c)

Both A and B

d)

none

9.

Which method is used to free memory occupied by an object?

a)

 del

b)

gc.collect()

c)

Both A and B

d)

none

10.

What will be the output of print(3 and 5 or 0 and 2)?

a)

5

b)

0

c)

3

d)

error

11.

 What will be the output of the following code?

class A:

    def init(self):

        self.x = 0

    def getattr(self, item):

        return item.upper()

obj = A()

print(obj.y)

a)

0

b)

 'y'

c)

'Y'

d)

AttributeError

12.

What is the output of the following code?

def func(x, y=[]):

    y.append(x)

    return y

print(func(1))

print(func(2))

print(func(3, []))

print(func(4))

a)

[1] [2] [3] [4]

b)

[1] [1, 2] [3] [1, 2, 4]

c)

[1] [1, 2] [3] [1, 2, 4]

d)

 [1] [2] [3] [4]

13.

What is the output of this Python snippet?

a = (1, 2, 3)

b = a[:]

print(a is b)

a)

true

b)

false

c)

error

d)

none

14.

What will be the output of the following code?

a = ([],)

a[0].append(1)

print(a)

a)

([], )

b)

([1], )

c)

error

d)

none

15.

What is the result of hash((1, 2, [3]))?

a)

Some hash value

b)

Error

c)

None

d)

0

16.

What will this code do?

from collections import deque

d = deque()

d.append(1)

d.appendleft(2)

print(d)

a)

[1, 2]

b)

[2, 1]

c)

deque([1, 2])

d)

deque([2, 1])

17.

What does this code print?

print('a' + 'b' * 3)

a)

'abbb'

b)

 'a3'

c)

 ['a', 'b', 'b', 'b']

d)

Error

18.

What will print(int('1' + '2' * 3)) output?

a)

5

b)

123

c)

1222

d)

Error

19.

What happens here?

print(list(map(str, range(3))))

a)

['1', '2', '3']

b)

['0', '1', '2']

c)

[0, 1, 2]

d)

Error

20.

What will be the output of this code?

class A:

    def init(self):

        self.value = 10

    def getattr(self, name):

        return name.upper()

a = A()

print(a.value, a.undefined_attr)

a)

10 UNDEFINED_ATTR

b)

 AttributeError

c)

10 None

d)

None UNDEFINED_ATTR