Overriding Built-in Functions for Polymorphism

Medium Polymorphism & Duck Typing
Solve in Playground →

Problem Statement

Create a `Team` class whose constructor takes a list of `members`. Overload the standard Python `len()` function by defining the `__len__(self)` magic method to return the number of members. Instantiate it with 3 names from input and print `len(team)`. Then iterate and print each member.

Input Format

A single line with comma-separated names.

Output Format

Print the length, then each name on a new line.

Constraints

None

Sample Input

Alice,Bob,Charlie

Sample Output

Size: 3
Alice
Bob
Charlie

Explanation

Polymorphism extends to Python's built-in functions. By defining __len__, your custom object behaves exactly like standard lists or strings when passed to len().

Starter Code

class Team:
    def __init__(self, members):
        self.members = members
    # Override __len__ here

if __name__ == '__main__':
    names = input().split(',')
    # Instantiate Team, print Size, and loop through members
    pass

Limits

  • Time Limit: 1s
  • Memory Limit: 256MB

Embedded C Programming

Updated: March 15, 2026
Intermediate

Embedded systems rely on efficient low-level programming to interact directly with hardware. In this course, you will learn how to write practical Embedded C programs used in real microcontroller-based systems. Rather than focusing only on theory, this course follows a practice-driven approach. Each lesson includes hands-on coding exercises that simulate real firmware development tasks used