Why don't string variables update when they are changed
<p>Say we have some code like so :</p>

<pre><code>placehold = "6"
string1 = "this is string one and %s" % placehold

print string1

placehold = "7"
print string1
</code></pre>

<p>When run, both of the print statements return as if placehold were ALWAYS 6. However, just before the second statement ran, placehold was changed to 7, so why does it not dynamically reflect in the string?</p>

<p>Also, would you be able to suggest a way to make the string return with 7?</p>

<p>Thank you</p>

<p><code>string1</code> will use whatever value of <code>placehold</code> existed at the time <code>string1</code> was declared. In your example, that value happens to be <code>"6"</code>. To get <code>string1</code> to "return with 7" you would need to reassign it (<code>string1 = "this is string one and %s" % placehold</code>) after changing the value of <code>placehold</code>.</p>

python string