Count Your Instances

Easy ⏱ 8 min 88% acceptance ★★★★★ 4.6
Give the class Session a class-level counter: every construction increments Session.count. Add a classmethod active() returning the current count. The counter must live on the class so all instances share it.

Examples

Example 1
Input
Session(); Session(); Session.active()
Output
2
Explanation

Two constructions bumped the shared counter.

Constraints

  • Increment inside __init__ via the class name (or type(self)).
  • active() is a classmethod.

Topics

OOPclass state

Companies

TCSHCLTechAccenture

Hints

Hint 1

Session.count += 1 mutates class state.

Hint 2

Initialize count = 0 in the class body.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.