ProgrammingVery hardGATE CS · Product-company placement
What is printed?
What is printed?
def register(cls):
cls.tag = cls.__name__.lower()
return cls
@register
class Alpha:
tag = "none"
class Beta(Alpha):
pass
print(Alpha.tag, Beta.tag)- A. alpha alpha
- B. alpha beta
- C. none beta
- D. alpha none
Correct answer: A. alpha alpha
A class decorator runs once on Alpha, overwriting Alpha.tag. Beta is not decorated; it simply inherits the class attribute 'alpha'.
More Python Programming questions
- What is printed? python class A: def hi(self): return "A" class B(A): pass class C(A): def hi(self): return "C" class D(B, C): pass…
- What is printed? python class A: def f(self): return "A" class B(A): def f(self): return "B" + super().f() class C(A): def f(self): return…
- What is printed? python class X: pass class Y: pass class A(X, Y): pass class B(Y, X): pass try: class C(A, B): pass print("ok") except…
- What is printed? python class Base: def init(self): print("Base", end=" ") class L(Base): def init(self): print("L", end=" ")…
- What is printed? python class A: x = "A" def get(self): return self.x class B(A): x = "B" b = B() A.x = "A2" b.x = "inst" del b.x…
- What is printed? python class Meta(type): def call(cls, a): print("meta", end=" ") return super().call(a) class K(metaclass=Meta): def…