title: How to pass string format as a variable to an f-string
body: <p>I am using f-strings, and I need to define a format that depends upon a variable.</p>
  
  <pre><code>def display_pattern(n):
      temp = ''
      for i in range(1, n + 1):
          temp = f'{i:&gt;3}' + temp
          print(temp)
  </code></pre>
  
  <p>If it is relevant, the output of <code>display_pattern(5)</code> is:</p>
  
  <pre><code>  1
    2  1
    3  2  1
    4  3  2  1
    5  4  3  2  1
  </code></pre>
  
  <p>I wonder if it is possible to manipulate the format <code>&gt;3</code>, and pass a variable instead. For example, I have tried the following:</p>
  
  <pre><code>def display_pattern(n):
      spacing = 4
      format_string = f'&gt;{spacing}' # this is '&gt;4'
      temp = ''
      for i in range(1, n + 1):
          temp = f'{i:format_string}' + temp
          print(temp)
  </code></pre>
  
  <p>However, I am getting the following error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "pyramid.py", line 15, in &lt;module&gt;
      display_pattern(8)
    File "pyramid.py", line 9, in display_pattern
      temp = f'{i:format_string}' + temp
  ValueError: Invalid format specifier
  </code></pre>
  
  <p>Is there any way I can make this code work? The main point is being able to control the spacing using a variable to determine the amount of padding.</p>