While playing with new f-strings in the recent Python 3.6 release, I've noticed the following:
We create a
foovariable with valuebar:>>> foo = 'bar'Then, we declare a new variable, which is our f-string, and it should take
footo be formatted:>>> baz = f'Hanging on in {foo}'Ok, all going fine and then we call
bazto check its value:>>> baz 'Hanging on in bar'Let's try to change the value of
fooand callbazagain:>>> foo = 'spam' >>> baz 'Hanging on in bar'
Shouldn't it be dynamic? Why does this happen? I thought the f-string would update if the value of foo changed, but this didn't happened. I don't understand how this works.
'Hanging on in ' + footo behave? - Josh Lee'hanging on in {}'.format(foo)- they don't keep a reference to the interpolated value. - jonrsharpestr.format. - ForceBrufoo = f'{foo}'to behave. - ThisSuitIsBlackNot