How to replace a variable in python from within code code example Example: python replace variable in string plot.savefig(f'hanning{num}.pdf') # added in Python 3.6