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>Because you have already assigned a value to that variable once you execute the statement.</p>

<p>It sounds like you'd rather need a function such as:</p>

<pre><code>def f(placehold):
    return "this is string one and %s" % placehold
</code></pre>

<p>Now you can <code>print(f("7"))</code> to achieve the desired functionality.</p>

python string