title: Looking for breakdown for a python replace substring script
body: <p>I'm learning this script of how to replace substrings in a string and i stumbled on the while loop and i didn't understand the use and logic behind using the before and after variables and generally how the while loop panned out. I checked online and i noticed they use the replace method but i want to understand this conventional step and logic. </p>
  
  <pre><code>things = "tree, box, chair, lamp, \n" \
      "desk, cat, dog, grass, \n" \
      "pig, box, lamp, shelf"
  print(things)
  print()
  
  old_item = input("Old item: ")
  new_item = input("New item: ")
  len_old_item = len(old_item) # i didn't get why they added this.
  
  i = things.find(old_item) 
  while i &gt; 0:
      before = things[:i] # i don't get how this part works
      after = things[i+len_old_item:] # i don't get how this part works
      things = before + new_item +after # i don't get how this part works
      i = things.find(old_item) # i don't get how this part works
  
  print()
  print(things)
  </code></pre>
  
  <p>The output asks the user to enter an old item from the list and then replaces it in the list of things with the new item.</p>