title: How to insert variable into escaped string literal?
body: <p>I'm calling an API that will require dynamic variables as parameters. However, I do not know how to format the string to include variables when it is surrounded by triple quotes and a backslash escape character at the beginning of the string literal. </p>
  
  <p>I've tried varying the amount of quotes and using the ".format()" function.</p>
  
  <p>Here is code formatted in a way that gets a successful result:</p>
  
  <pre><code>payload = "{\n\t\"firm\": \"myfirm\",\n\t\"id\": \"f87987562\",\n\t\"data\": {\n\t\t\"tracking_preference\": 2\n\t} \n}\n"
  </code></pre>
  
  <p>Here is my attempt at trying to format the string in a cleaner way while also including variables:</p>
  
  <pre><code>payload = \
      """{
      "firm": {0},
      "id": {1},
      "data": {
          "tracking_preference": {2}
      } 
  }
  """.format('myfirm', "f87987562", 2)
  </code></pre>
  
  <p>This is the error that I am receiving:</p>
  
  <pre><code>     19     } 
       20 }
  ---&gt; 21 """.format('myfirm', "f87987562", 2)
       22 
       23 apikey = "secret_key"
  
  KeyError: '\n    "firm"'
  </code></pre>
  
  <p>I suspect it has something to do with the backslash, but its implementation seems necessary. Any help and insight on the intuition behind this string formatting is greatly appreciated.</p>
  
  <p>I am trying to pass the string literal into the request function:</p>
  
  <pre><code>response = requests.request("POST", url, data=payload, headers=headers)
  </code></pre>