title: Create a msg variable to use instead of repeating multiline strings
body: <p>I have several functions in my script that use multiline strings for messages currently.</p>
  <p>My script is a password reminder that checks if a user is within 30, 15, 3 days from expiration, if they are they are sent sms and email reminders to change their password. In this function I have the body section as a multiline string at the moment:</p>
  <pre><code>        def send_sms():
              client = Client(twilio_account_sid, twilio_auth_token)
              for d in notify_users:
                  message = client.messages.create(
                      to=d['Number'],
                      from_=twilio_from_phone_number,
                      body=f&quot;Hello {d['Name']}, you have {d['days']} days left to reset your password.&quot;
                           f&quot;\n&quot;
                           f&quot;\n***To change your password, press CTRL + ALT + DEL and select change password***.&quot;
                           f&quot;\n&quot;
                           f&quot;\n&quot;
                           f&quot;\n- MY COMPANY IT&quot;)
                  print(message.sid)
              for d in expired_users:
                  message = client.messages.create(
                      to=d['Number'],
                      from_=twilio_from_phone_number,
                      body=f&quot;Hello {d['Name']}, your password has expired, please change it asap to avoid any issues that could occur with your account.&quot;
                           f&quot;\n&quot;
                           f&quot;\n***To change your password, press CTRL + ALT + DEL and select change password***.&quot;
                           f&quot;\n&quot;
                           f&quot;\n&quot;
                           f&quot;\n- MY COMPANY IT&quot;)
                  print(message.sid)
  </code></pre>
  <p>basically I want to replace the body sections of these functions with a notify_msg or expired_msg variable</p>
  <p>I tried to define this before the function like so:</p>
  <pre><code>notify_msg = (f&quot;Hello {d['Name']}, you have {d['days']} days left to reset your password.&quot;
                       f&quot;\n&quot;
                       f&quot;\n***To change your password, press CTRL + ALT + DEL and select change password***.&quot;
                       f&quot;\n&quot;
                       f&quot;\n&quot;
                       f&quot;\n- MY COMPANY IT&quot;)
  expired_msg = (f&quot;Hello {d['Name']}, your password has expired, please change it asap to avoid any issues that could occur with your account.&quot;
                        f&quot;\n&quot;
                        f&quot;\n***To change your password, press CTRL + ALT + DEL and select change password***.&quot;
                        f&quot;\n&quot;
                        f&quot;\n&quot;
                        f&quot;\n- MY COMPANY IT&quot;)
  </code></pre>
  <p>but obviously this isn't going to work because &quot;d&quot; isn't defined. I thought about doing this within the forloop, but I want the same variables to be able to be used in my send_email() functions as well. What could I do to pass this in, so I don't have to repeat the same multiline strings several times?</p>
  <p>Here is the same thing for the email function:</p>
  <pre><code> #  Send email to users
          def send_emails():
              for d in notify_users:
                  return requests.post(
                      &quot;https://api.mailgun.net/v3/MYDOMAIN/messages&quot;, 
                      auth=(&quot;api&quot;, &quot;MAILGUN_API_KEY&quot;),
                      data={&quot;from&quot;: &quot;IT &lt;mailgun@MYDOMAIN&gt;&quot;,
                            &quot;to&quot;: notify_list,
                            &quot;subject&quot;: &quot;Password Reminder&quot;,
                            &quot;text&quot;: f&quot;Hello {d['Name']}, you have {d['days']} days left to reset your password.&quot;
                                    f&quot;\n&quot;
                                    f&quot;\n***To change your password, press CTRL + ALT + DEL and select change password***.&quot;
                                    f&quot;\n&quot;
                                    f&quot;\n&quot;
                                    f&quot;\n- IT&quot;})
  
          # Send email to expired users
          def send_exp_emails():
              for d in expired_users:
                  return requests.post(
                      &quot;https://api.mailgun.net/v3/MYDOMAIN/messages&quot;,
                      auth=(&quot;api&quot;, &quot;MAILGUN_API_KEY&quot;),
                      data={&quot;from&quot;: &quot;IT &lt;mailgun@MYDOMAIN&gt;&quot;,
                            &quot;to&quot;: expired_list,
                            &quot;subject&quot;: &quot;Password Reminder&quot;,
                            &quot;text&quot;: f&quot;Hello {d['Name']}, your password has expired, please change it asap to avoid any issues that could occur with your account.&quot;
                                    f&quot;\n&quot;
                                    f&quot;\n***To change your password, press CTRL + ALT + DEL and select change password***.&quot;
                                    f&quot;\n&quot;
                                    f&quot;\n&quot;
                                    f&quot;\n- IT&quot;})
  </code></pre>
  <p>As you see, I am repeating the same multiline strings 4 times in my script.
  Is there anything I can do to pass multiline string variables in the body instead of repeating the same lines? Thanks all.</p>
  <p>UPDATED CODE</p>
  <pre><code>users = [
  {'Name': 'Timmy Turner', 'Number':'3245234523', 'Email':'timmyt@gmail.com','days': 15},    
  {'Name': 'Jimmy Fallon', 'Number':'3245234523', 'Email':'jimmyfallon@gmail.com','days': 30}
  ]
  expired_users = [
  {'Name': 'Timmy Turner', 'Number':'3245234523', 'Email':'timmyt@gmail.com','days': -4},    
  {'Name': 'Jimmy Fallon', 'Number':'3245234523', 'Email':'jimmyfallon@gmail.com','days': -5}
  ]
  
  msg = &quot;Hello % , %. \n \n***To change your password, press CTRL + ALT + DEL and select change password***.\n\n\n- MY COMPANY IT&quot;
  
  def send_email():
      for d in users:
          return requests.post(
              &quot;https://api.mailgun.net/v3/MYDOMAIN/messages&quot;,
              auth=(&quot;api&quot;, &quot;MAILGUN_API_KEY&quot;),
              data={&quot;from&quot;: &quot;IT &lt;mailgun@mail.MYDOMAIN.net&gt;&quot;,
                  &quot;to&quot;: emails,
                  &quot;subject&quot;: &quot;Password Reminder&quot;,
                  &quot;text&quot;: msg % (d['Name'], f&quot;you have {d['days']} days left to reset your password.&quot;)})
  
  def send_expired():
      for d in expired_users:
          return requests.post(
              &quot;https://api.mailgun.net/v3/MYDOMAIN/messages&quot;,
              auth=(&quot;api&quot;, &quot;MAILGUN_API_KEY&quot;),
              data={&quot;from&quot;: &quot;IT &lt;mailgun@mail.MYDOMAIN.net&gt;&quot;,
                  &quot;to&quot;: expired,
                  &quot;subject&quot;: &quot;Password Reminder&quot;,
                  &quot;text&quot;: msg% (d['Name'], &quot;your password has expired, please change it asap to avoid any issues that could occur with your account&quot;)})
  </code></pre>