iGET

Python Programming - MCQ Practice Questions

Core Python MCQs — syntax, data types, OOP, libraries for placements & IT exams.

189 questions | 100% Free

Q.1Medium

What will be the output of the following code? class Animal: def __init__(self, name): self.name = name def speak(self): return 'Some sound' class Dog(Animal): def speak(self): return 'Woof' d = Dog('Rex') print(d.speak())

Q.2Medium

Which of the following best describes the purpose of the __str__ method in a Python class?

Q.3Medium

What will be the output of the following code? class Counter: count = 0 def __init__(self): Counter.count += 1 a = Counter() b = Counter() c = Counter() print(Counter.count)

Q.4Medium

What will be the output of the following code? class MyClass: def __init__(self, x): self.__x = x obj = MyClass(10) print(obj.__x)

Q.5Medium

Which of the following correctly defines a class method in Python?

Q.6Medium

What is the output of the following code? class Shape: def area(self): return 0 class Circle(Shape): def __init__(self, r): self.r = r def area(self): return 3.14 * self.r * self.r shapes = [Shape(), Circle(7)] for s in shapes: print(s.area())

Q.7Medium

What will be the output of the following code? class A: def greet(self): return 'Hello from A' class B(A): def greet(self): return super().greet() + ' and B' obj = B() print(obj.greet())

Q.8Medium

What will be the output of the following code? class Vehicle: def __init__(self, brand): self.brand = brand class Car(Vehicle): def __init__(self, brand, model): super().__init__(brand) self.model = model c = Car('Toyota', 'Camry') print(c.brand, c.model)

Q.9Medium

What is the output of the following code? class Box: def __init__(self, vol): self.vol = vol def __gt__(self, other): return self.vol > other.vol b1 = Box(10) b2 = Box(20) print(b1 > b2)

Q.10Medium

What will be the output of the following code? class Foo: def __init__(self): self.x = 10 def bar(self): self.x += 5 return self.x obj1 = Foo() obj2 = Foo() obj1.bar() print(obj1.x, obj2.x)