Quiz Catalog

Catalog of quizzes

class A:
  x = 1

class B:
  pass

class C(A):
  pass

B.x = 2
A.x = 3

print(A.x, B.x, C.x)
3 2 3
  • class/variable

class Vehicle:
  def __init__(self, speed):
    if speed > 240:
      print(self.speed)
    self.speed = speed

car = Vehicle(350);
AttributeError: 'Vehicle' object has no attribute 'speed' 
  • class/variable

class SimpleClass:
  val = 1
  def __init__(self, n):
    val = n

s = SimpleClass(5)
print(s.val)
1
  • class/variable

class Test:
  def __init__(self, value):
      self.value = value

X = Test(2)
print(X(3))
TypeError: 'Test' object is not callable
  • class/variable