How to access a variable which is declared in some other function?
<pre><code>      def main():
                 x=2
      def cool():
                 y=4

nonlocal x
print (x)
</code></pre>

<p>It is showing an error as --nonlocal x is a invalid syntax--.And if I dont declare it as nonlocal it says undefined x. So, how do i acess a variable which is in some other function ?Now how do i access x variable  which is defined at main().</p>
