Python Classes & Objects
💡
Exercise 36

Favorite Cities 15 XP Easy

Ctrl+Enter Run Ctrl+S Save

Classes can contain lists as attributes, making them powerful for organizing data.

The __str__ method controls what happens when you print() an object.

📋 Instructions
Create a `City` class with: - Attributes: `name`, `country`, `population` (in millions) - Method `__str__()` that returns a formatted string Create a list of 3 cities and print them: ``` Tokyo, Japan - 14.0M people New York, USA - 8.3M people London, UK - 9.0M people ```
Use def __str__(self): return f'{self.name}, {self.country} - {self.population}M people'
🧪 Test Cases
Input
Run your code
Expected
Tokyo, Japan - 14.0M people New York, USA - 8.3M people London, UK - 9.0M people
Expected program output
main.py
Hi! I'm Rex 👋
Output
Ready. Press ▶ Run or Ctrl+Enter.