title: Assign a variable value in an if or while statement
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/542212/is-there-any-way-to-do-variable-assignments-directly-inside-a-whilehere-loop">Is there any way to do variable assignments directly inside a while(&lt;here&gt;) loop in Python?</a>  </p>
  </blockquote>
  
  
  
  <p>Sorry about such a basic question. I'm trying to learn Python, but really haven't found an answer to this.</p>
  
  <p>In Python, can I assign a value to a variable in a <code>while</code> or <code>if</code> statement? If so, how? </p>
  
  <p>For example. I had to do this:</p>
  
  <pre><code>line_list = []
  while True:
      line = raw_input("&gt;&gt;&gt; ")
      if not line: break
      line_list.append(line)
  print line_list
  </code></pre>
  
  <p>But I'd like to do this:</p>
  
  <pre><code>line_list = []
  while line = raw_input("&gt;&gt;&gt; "):
      line_list.append(line)
  print line_list
  </code></pre>
  
  <p>The tutorials I'm looking at don't mention this one way or another, but this is a common construct in most other languages.</p>