Given code (Python3):
class A:
# your code
def f():
print('hi')
a = A()
a.f()
Given code (Python3):
class A:
# your code
def f():
print('hi')
a = A()
A.f()
You are required to print Method Resolution Order (MRO) for class D.
Which method would you use and what will be the order of the classes?
Which method would you use and what will be the order of the classes?
Anonymous Quiz
39%
__mro__ and D, C, A, B, object
4%
mro and D, C, A, B, object
7%
__mro__ and D, C, B, A, object
0%
mro and D, C, B, A, object
7%
__mro__ and C, A, B
18%
__mro__ and D, C, A, B
4%
__mro__ and D, C, B, A
0%
__mro__ and D, C, A
4%
There's no such method
18%
See solution
What will this code do?
import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6]])
print(a.reshape(1, -1))
Choose your answer
Anonymous Quiz
35%
[[1 2 3 4 5 6]]
26%
[1, 2, 3, 4, 5, 6]
21%
[[1], [2], [3], [4], [5], [6]]
5%
[1]
14%
See solution
What will this code do?
class A:
def __repr__(self):
return "repr"
def __str__(self):
return "str"
a = A()
print(a, repr(a), str(a))
Choose your answer
Anonymous Quiz
4%
str str str
8%
repr str repr
52%
str repr str
31%
repr repr str
2%
str repr repr
0%
repr repr repr
2%
See solution
Choose your answer
Anonymous Quiz
9%
'3'
2%
[3]
11%
ord('3')
2%
ord('3')
42%
3
7%
51
15%
'0b11'
2%
bin(3)
11%
See solution
What will this code do?
(lambda: lambda: lambda: lambda: lambda: 1)()()()()()
Choose your answer
Anonymous Quiz
3%
None
37%
1
3%
lambda
25%
<function <lambda> at 0x110a8ae18>
0%
TypeError
29%
SyntaxError
4%
See solution
Choose your answer
Anonymous Quiz
2%
None
12%
1
58%
3
3%
lambda
9%
<function <lambda> at 0x110a8ae18>
8%
TypeError
9%
SyntaxError
0%
SyntaxError
Choose your answer
Anonymous Quiz
2%
None
5%
1
52%
3
3%
lambda
7%
<function <lambda> at 0x110a8ae18>
7%
TypeError
22%
SyntaxError
2%
SyntaxError
What do you need to add to make the code work?
class A:
def __init__(self, x):
self.x = x
def __and__(self, other):
return self.x + other.x
a1 = A(1)
a2 = A(2)
# your code
output: 3