Count how many times a variable is called
<p>I want to add something that will count how many times a variable is used (like variable <code>c</code>) and output in number of times variable <code>c</code> was used. What functions can I use? Here's the code:</p>

<pre><code>#! /usr/bin/python

question = raw_input
y = "Blah"
c = "Blahblahb"


print "Is bacon awesome"
if question() = "Yes":
    print y
else:
    print c

print "Blah"
if question() = "Yes":
    print y
else:
    print c
</code></pre>

<p>You will have to increment a counter and there a many ways to do that. One way is to encapsulate in a <code>class</code> and use <code>property</code>, but this uses more advanced features of python:</p>

<pre><code>class A(object):
    def __init__(self):
        self.y_count = 0

    @property
    def y(self):
        self.y_count += 1
        return 'Blah'

a = A()
print(a.y)
# Blah
print(a.y)
# Blah
print(a.y)
# Blah
print(a.y_count)
# 3
</code></pre>

python variables counting