UnboundLocalError: local variable 'k' referenced before assignment
<p>I have read <a href="https://stackoverflow.com/questions/17097273/unboundlocalerror-local-variable-referenced-before-assignment">StackQ1</a> and <a href="https://stackoverflow.com/questions/20873285/unboundlocalerror-local-variable-input-referenced-before-assignment">stackQ2</a> But unable to solve my error. 
The given below program is giving </p>

<blockquote>
  <p>UnboundLocalError: local variable 'k' referenced before assignment</p>
</blockquote>

<p>I already made variable <code>k</code> as <code>global</code> but it is not working.</p>

<pre><code>class myClass:
    global k
    k=0
    def data(self):
        def data2(k):
                for j in range(5):
                    k=k+1
                    return k
        for i in range(5):
            k=k+1
            data2(k)

Obj = myClass()
print(Obj.data())
</code></pre>

<p>I also tried as </p>

<pre><code>k=0
class myClass:
#     global k

    def data(self):
        def data2(k):
                for j in range(5):
                    k=k+1
                    return k
        for i in range(5):
            k=k+1
            data2(k)

Obj = myClass()
print(Obj.data())
</code></pre>

<p>But not working.</p>

<pre><code>class My_Class(object):
     def __init__(self, **kwargs):
         super(My_Class, self).__init__()
         self.k = "hello"
     def data(self, *args):
         print "call data"
         return self.k


my_class = My_Class()
print my_class.data() 
</code></pre>

python