Why Python scope my variable outside my function?
<p>i start with Python. I like to try new language. So i've got a "simple" problem about scope and Python.</p>

<p>Here is a recursive function</p>

<pre><code>def foo(myarray)
  if myarray == False: 
    myarray = [[0] * 5 for _ in range(5)]
    myarray[0][0] = 1
  "some code ..."
  foo(myarray)

myarray = False
foo(myarray)
</code></pre>

<p>I don't want to share my var "myarray" in global env. I juste want Python scope "myarray" only in the function not outside. But Python shared "myarray" as it were a global var. How can restrict the scope to the function ?</p>

<p>Disregarding the myriad of syntax errors, your <code>myarray</code> variable seems to be declared globally and that's why it has global scope?</p>

python python-3.x