title: Python "if" statement changes variable value
body: <p>This code is from a beginning python book I'm studying, the chapter is discussing Dictionaries.</p>
  
  <pre><code>favorite_languages = { 
      'jen': 'python',
      'sarah': 'c',
      'edward': 'ruby',
      'phil': 'python',
      }
  
  friends = ['phil','sarah']
  
  for name in favorite_languages.keys():
      print(name.title())
  
      if name in friends:
          print(" hi " +name.title() +
              ", i see your favorite language is " +
              favorite_languages[name].title() + "!")
  
  The result is:
  
  Jen 
  Ed 
  Phil 
   hi Phil, i see your favorite language is Python! 
   hi Sarah, i see your favorite language is C!
  </code></pre>
  
  <p>I'm having trouble understanding the logic of the code relative to the varible "name" and why the value changed. Meaning, the variable "name" is created by the "for" loop and all the Dictionary keys are stored in it, so that when the "if" statement begins the value of "name" is all keys. </p>
  
  <p>My understanding of the "if" statement is that it just returns a boolean value of true or false, in this case true. But why does the value of "name" (as a result of this "if" statement) get changed to the value of "friends" at this point?</p>
  
  <p>Is it just a rule that is built into Python? Because it does not logically follow, unless I'm missing something.</p>
  
  <p>It would make more sense to me to write it:</p>
  
  <pre><code>if friends in name:
      print(" hi " friends.title() +
  </code></pre>