String Representation (__str__)

Easy Magic Methods & Operator Overloading
Solve in Playground →

Problem Statement

Create a `Book` class with `title` and `author`. Overload the `__str__` method to return a user-friendly string: ‘[Title] by [Author]’. Read the inputs, instantiate the book, and print the object directly using `print(book)`.

Input Format

Two lines: Title on the first, Author on the second.

Output Format

Print the formatted string.

Constraints

None

Sample Input

1984
George Orwell

Sample Output

1984 by George Orwell

Explanation

The `__str__` method defines what is displayed when an object is passed to `print()` or `str()`, aimed at end users.

Starter Code

class Book:
    # Define __init__ and __str__
    pass

if __name__ == '__main__':
    t = input().strip()
    a = input().strip()
    # Instantiate and print
    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