text: Q:
  
  Trying to format a connection string in Python - unable to replace with variable
  
  I am trying to create a connection string in Python - the goal is to have a list of tables/servers to access and it'll iterate through based on a list earlier.
  I've got the query written (using """select * from """ worked) , but I cannot seem to get the connection string to behave. Yes. the "{SQL Server}" needs to be in curly-brackets.
  server_name = "myservername"
  
  #this doesn't work:
  con_string = ('Driver={{SQL Server}};Server={server_name};Database={mydatabase};App=myappname;Trusted_Connection=yes')
  
  Nor does this 
  con_string = ('Driver={{SQL Server}};'
                'Server={};'.format(server_name)
                'Database=mydatabase;'
                'App=myappname;'  # It's not "application name"!
                'Trusted_Connection=yes')
  
  Nor this:
  serverstring = 'Server={};'.format(server_name)
  con_string = ('Driver={{SQL Server}};'
                '{serverstring}'
                'Database=mydatabase;'
                'App=myappname;'  # It's not "application name"!
                'Trusted_Connection=yes')
  
  Any help greatly appreciated.
  
  A:
  
  To create a format string you need f at the beginning. So, for example, your third example should be:
  serverstring = 'Server={};'.format(server_name)
  con_string = ('Driver={{SQL Server}};'
                f'{serverstring}'
                'Database=mydatabase;'
                'App=myappname;'  # It's not "application name"!
                'Trusted_Connection=yes')
  
  