title: after assigning a variable to a function. Why does the variable change every time the function is executed?
body: <p>when I assign a variable <code>X</code> to a function (<code>f</code>), its output is a list. variable <code>X</code> changes after every time that I execute my function <code>f</code> in everywhere in my project.</p>
  <p>the project is about reinforcement learning. I have trouble with recording my states in the environment. when I append visited states to a list named <code>state_history</code> all appended states will be changing after each run of <code>environment</code> function and all states convert to the last state.
  I write a pseudo code here so you can regenerate my problem.</p>
  <pre><code># this function takes current state in dictionary format, increment it's value and returns next state 
  def env_(current_state):
  
      nex_state=current_state['current state'] +1
      current_state['current state']=nex_state
     
      return current_state
  # i run function 10 times 
  state_history=[]
  # initializing state
  initial_state={}
  initial_state['current state']=0
  for i in range(10):
      nex_state=env_(initial_state)
      state_history.append(nex_state)
      initial_state=nex_state
  print(state_history)
  </code></pre>
  <p>here is the result:
  all appended states converted to the last state.</p>
  <pre><code>[{'current state': 10}, {'current state': 10}, {'current state': 10}, {'current state': 10}, {'current state': 10}, {'current state': 10}, {'current state': 10}, {'current state': 10}, {'current state': 10}, {'current state': 10}]    
  </code></pre>
  <p>the expected result was:</p>
  <pre><code>[{'current state': 1}, {'current state': 2}, {'current state': 3}, {'current state': 4}, {'current state': 5}, {'current state': 6}, {'current state': 7}, {'current state': 8}, {'current state': 9}, {'current state': 10}]
  
  
     
  </code></pre>