All quizzesEasy
Classes & Instances — Series 2
Preview — 3 of 10 questions
What is the output of the following code?
javascript
class Foo:
def __init__(self):
return 42
f = Foo()ATypeError: __init__() should return None, not 'int'
Bf = Foo() succeeds, and f is simply the integer 42.
Cf = Foo() succeeds normally; the return 42 is silently ignored.
DSyntaxError: 'return' outside function
What is the output of the following code?
javascript
class A:
value = "A"
class B:
value = "B"
class C(A, B):
pass
print(C.value)
print(C().value)AA, then B
BB, then B
CA, then A
DAttributeError: 'C' object has no attribute 'value'
What is the output of the following code?
javascript
class Animal:
pass
class Dog(Animal):
pass
d = Dog()
print(isinstance(d, Animal))
print(type(d) == Animal)
print(type(d) == Dog)ATrue, True, True
BTrue, False, True
CFalse, False, True
DTrue, False, False
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.