There are a few cases where you won't be able to use f-strings. First, you can't reuse a single template string with different variables. Second, f-strings were introduced in Python 3.6. If you're stuck on an older version of Python or need to reuse template strings, you can use the older str.format method instead. It uses the same formatting specifiers as f-strings, but can be called multiple times on one string. Here's an example:
>>> template = "abc {number:*^10d}"
>>> template.format(number=32)
'abc ****32****'
>>> template.format(number=84)
'abc ****84****'
The format method behaves similarly to f-strings, but there are a couple of differences:
- It is restricted in what it can look up. You can access attributes on objects or look up an index in a list or dict, but you can't call a function inside the template string.
- You can use integers to access positional arguments passed to the format method: "{0} world".format('bonjour'). The indexes are optional if you specify the variables in order: "{} {}".format('hello', 'world').