Flexible Object Arguments (*args with objects)

Medium Polymorphism & Duck Typing
Solve in Playground →

Problem Statement

Create a function `process_items(*args)`. Iterate through `args`. Use `hasattr(item, ‘process’)` to check if the object has a `process` method. If it does, call it. If not, print ‘Cannot process’. Create `Data` (has process) and `Value` (no process) classes. Pass `Data()`, `Value()`, and `Data()`.

Input Format

None

Output Format

Print the outputs sequentially.

Constraints

None

Sample Output

Processing Data
Cannot process
Processing Data

Explanation

Combining *args with hasattr() enables building incredibly flexible APIs that can consume any number of strictly typed or duck-typed objects safely.

Starter Code

class Data:
    def process(self):
        print('Processing Data')

class Value:
    pass

def process_items(*args):
    # Write iteration and hasattr check here
    pass

if __name__ == '__main__':
    # Call process_items with instances
    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