title: python - How to format variable number of arguments into a string?
body: <p>We know that formatting <strong>one</strong> argument can be done using <strong>one</strong> <code>%s</code> in a string:</p>
  
  <pre><code>&gt;&gt;&gt; "Hello %s" % "world"
  'Hello world'
  </code></pre>
  
  <p>for two arguments, we can use two <code>%s</code> (duh!):</p>
  
  <pre><code>&gt;&gt;&gt; "Hello %s, %s" % ("John", "Joe")
  'Hello John, Joe'
  </code></pre>
  
  <p>So, how can I format a variable number of arguments <em>without having to explicitly define within the base string a number of <code>%s</code> equal to the number of arguments to format</em>? it would be very cool if something like this exists:</p>
  
  <pre><code>&gt;&gt;&gt; "Hello &lt;cool_operator_here&gt;" % ("John", "Joe", "Mary")
  Hello JohnJoeMary
  &gt;&gt;&gt; "Hello &lt;cool_operator_here&gt;" % ("John", "Joe", "Mary", "Rick", "Sophie")
  Hello JohnJoeMaryRickSophie
  </code></pre>
  
  <p>Is this even possible or the only thing I could do about it is to do something like:</p>
  
  <pre><code>&gt;&gt;&gt; my_args = ["John", "Joe", "Mary"]
  &gt;&gt;&gt; my_str = "Hello " + ("".join(["%s"] * len(my_args)))
  &gt;&gt;&gt; my_str % tuple(my_args)
  "Hello JohnJoeMary"
  </code></pre>
  
  <p>NOTE: I <strong>need</strong> to do it with the <code>%s</code> string formatting operator.</p>
  
  <p><strong>UPDATE</strong>:</p>
  
  <p>It needs to be with the <code>%s</code> because a function from another library formats my string using that operator given that I pass the unformatted string and the args to format it, but it makes some checking and corrections (if needed) on the args before actually making the formatting. </p>
  
  <p>So I need to call it:</p>
  
  <pre><code>&gt;&gt;&gt; function_in_library("Hello &lt;cool_operator_here&gt;", ["John", "Joe", "Mary"])
  "Hello JohnJoeMary"
  </code></pre>
  
  <p>Thanks for your help!</p>