Basic usage
Input
C = type('C',(InstanceCounter,),{}); a = C(); b = C(); (C.total_created(), C.current_alive())
Output
(2, 2)
Two instances of class C were created; both are currently alive.
Full lesson preview
Implement a class that tracks how many instances of each class have been created and how many are currently alive.
Problem statement
Task
Examples
Input
C = type('C',(InstanceCounter,),{}); a = C(); b = C(); (C.total_created(), C.current_alive())
Output
(2, 2)
Two instances of class C were created; both are currently alive.
Input format
Output format
Constraints
Samples
Input
A = type('A',(InstanceCounter,),{}); [A() for _ in range(3)]; A.total_created()
Output
3
Three instances of subclass A were created; total_created returns 3.