在 Ruby 1.9 中,我可以使用它的类变量,如下所示:
class Sample
@@count = 0
def initialize
@@count += 1
end
def count
@@count
end
end
sample = Sample.new
puts sample.count # Output: 1
sample2 = Sample.new
puts sample2.count # Output: 2
如何在 Python 2.5+ 中实现上述目标?