Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Full lesson preview

Return a Summary of Object Data

Create a simple class and implement a method that returns a human-readable summary of an object's attributes.

Python practice8 minClasses & Objects FundamentalsBeginnerLast updated April 7, 2026

Problem statement

Define a Person class that stores a name, age, and city. Implement a summary() instance method that returns a string formatted exactly as: "{name} ({age}) from {city}". The method should work for any name (including spaces), integer ages (including 0 or negative), and any city string (including the empty string).

Task

Define a class with an __init__ constructor and implement an instance method that returns a formatted string summarizing the instance data.

Examples

Basic example

Input

Person('Alice', 30, 'NY').summary()

Output

Alice (30) from NY

Creates a Person with name 'Alice', age 30, city 'NY' and returns the formatted summary.

Input format

A Person object is constructed with three arguments: name (str), age (int), city (str).

Output format

A single string like: "Name (Age) from City".

Constraints

Do not print anything in the summary method; return the formatted string. Keep the exact spacing and punctuation.

Samples

Sample 1

Input

Person('Bob', 0, 'London').summary()

Output

Bob (0) from London

Age can be zero.