Learn with Yasir

Share Your Feedback

polymorphism in Python - True or False Questions with Answers


Test your understanding of Object-Oriented Programming (OOP) in Python with these carefully crafted True or False questions on polymorphism. Great for beginners and intermediate learners to reinforce OOP concepts.

๐Ÿ” True or False

๐ŸŸข Beginner

  1. In Python, polymorphism is only possible through inheritance.
  2. Answer

    โŒ False โ€“ Polymorphism in Python can be achieved through both inheritance (method overriding) and duck typing (shared interfaces), not just inheritance.


  3. Polymorphism allows objects of different classes to be treated as objects of a common superclass.
  4. Answer

    โœ… True โ€“ Polymorphism enables treating different class instances through a common interface, allowing for flexible and reusable code.


  5. The built-in len() function in Python is an example of polymorphism.
  6. Answer

    โœ… True โ€“ The len() function works with different types (strings, lists, tuples, etc.) because they all implement the __len__() method, demonstrating polymorphism.


  7. The + operator in Python behaves differently with strings and numbers, demonstrating polymorphism.
  8. Answer

    โœ… True โ€“ The + operator performs concatenation with strings and addition with numbers, showing operator overloading which is a form of polymorphism.


๐ŸŸก Intermediate

  1. Method overloading is a common way to achieve polymorphism in Python.
  2. Answer

    โŒ False โ€“ Python doesn't support method overloading (multiple methods with same name but different parameters) in the traditional sense. Polymorphism is typically achieved through method overriding or duck typing.


  3. Duck typing is a form of polymorphism where the suitability of an object is determined by the presence of certain methods and properties.
  4. Answer

    โœ… True โ€“ Duck typing ("if it walks like a duck and quacks like a duck...") is a Pythonic approach to polymorphism that focuses on an object's behavior rather than its type.


๐Ÿ”ด Advanced

  1. Python's abstract base classes (ABCs) prevent polymorphism from occurring.
  2. Answer

    โŒ False โ€“ ABCs actually facilitate polymorphism by enforcing a common interface that subclasses must implement, while still allowing different implementations.


๐Ÿ“š Related Resources


๐Ÿง  Practice & Progress

Explore More Topics

Python Fundamentals

Flow Control Statements


Python Functions


Fundamentals more ...




๐Ÿง  Python Advanced

Object-Oriented Programming in Python (OOP)

More...

๐Ÿง  Modules