title: Python: Why do these lines of code display different values?
body: <p>I am relatively new to coding and python and I am trying to wrap my head round some concepts. One I am struggling on is the split() function and why these two pieces of code produce two different outputs</p>
  
  <pre><code>y = ["hello\n", "world\n", "python\n"]
  x = [line.strip() for line in y]
  print(x)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>y = ["hello\n", "world\n", "python\n"]
  for line in y:
      x = [line.strip()]
  print(x)
  </code></pre>
  
  <p>The first piece of code produces an output of </p>
  
  <pre><code>['hello', 'world', 'python']
  </code></pre>
  
  <p>Whilst the second produces</p>
  
  <pre><code>['python']
  </code></pre>
  
  <p>Does anyone know why this is, as to me they should do the same thing by both producing an output of </p>
  
  <pre><code>['python']
  </code></pre>
  
  <p>thanks </p>