79091408

Date: 2024-10-15 19:09:10
Score: 1
Natty:
Report link

Variant of @kdubs answer in the case that you would like to return a value from the class-qua-function:

class incrementer:
    state = 0

    def __new__(_class, increment = 1):
        _class.state += increment
        return _class.state

# Usage example:
one = incrementer()
two = incrementer() 
twelve = incrementer(10)
Reasons:
  • Has code block (-0.5):
  • User mentioned (1): @kdubs
  • Low reputation (0.5):
Posted by: Glen Whitney