Non-empty cart is truthy
Input
bool(ShoppingCart([('apple', 2)]))
Output
True
The cart has a single item with quantity 2, so the cart is truthy.
Full lesson preview
Learn how to control an object's truth value by implementing __bool__ so instances behave naturally in boolean contexts.
Problem statement
Task
Examples
Input
bool(ShoppingCart([('apple', 2)]))
Output
True
The cart has a single item with quantity 2, so the cart is truthy.
Input format
Output format
Constraints
Samples
Input
bool(ShoppingCart([('banana', 0), ('pear', 1.5)]))
Output
True
One item has a positive quantity (1.5), so the cart is truthy.