NEW
Font size
WorksheetsByteTheSnake
Total questions: 20
Worksheet time: 20mins
What is the output of print(2 == 2.0 is True)?
True
False
Error
None
What does slots do in Python?
Limits instance attributes
Defines private variables
Increases execution speed
Both A and C
What is the output of print(5 and 0 or 3)?
0
3
5
Error
print({True: 'yes', 1: 'no', 1.0: 'maybe'})
{True: 'yes', 1: 'no', 1.0: 'maybe'}
{True: 'maybe'}
{True: 'yes'}
{True: 'maybe'}
What will print(hash((1, 2, 3))) return?
A unique integer
A string
An error
None
What will be the output of print(0.1 + 0.2 == 0.3)?
True
False
Error
None
What is the output of bool(set())?
True
False
Error
none
What does islice() from itertools do?
Slices an iterable without converting it to a list
Works like list[start:stop]
Both A and B
none
Which method is used to free memory occupied by an object?
del
gc.collect()
Both A and B
none
What will be the output of print(3 and 5 or 0 and 2)?
5
0
3
error
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)
0
'y'
'Y'
AttributeError
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))
[1] [2] [3] [4]
[1] [1, 2] [3] [1, 2, 4]
[1] [1, 2] [3] [1, 2, 4]
[1] [2] [3] [4]
What is the output of this Python snippet?
a = (1, 2, 3)
b = a[:]
print(a is b)
true
false
error
none
What will be the output of the following code?
a = ([],)
a[0].append(1)
print(a)
([], )
([1], )
error
none
What is the result of hash((1, 2, [3]))?
Some hash value
Error
None
0
What will this code do?
from collections import deque
d = deque()
d.append(1)
d.appendleft(2)
print(d)
[1, 2]
[2, 1]
deque([1, 2])
deque([2, 1])
What does this code print?
print('a' + 'b' * 3)
'abbb'
'a3'
['a', 'b', 'b', 'b']
Error
What will print(int('1' + '2' * 3)) output?
5
123
1222
Error
What happens here?
print(list(map(str, range(3))))
['1', '2', '3']
['0', '1', '2']
[0, 1, 2]
Error
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)
10 UNDEFINED_ATTR
AttributeError
10 None
None UNDEFINED_ATTR
