String multiplication versus for loop
<p>I was solving a Python question on CodingBat.com. I wrote following code for a simple problem of printing a string n times- </p>

<pre><code>def string_times(str, n):
    return n * str
</code></pre>

<p>Official result is - </p>

<pre><code>def string_times(str, n):
    result = ""
    for i in range(n):
       result = result + str
    return result

print string_times('hello',3)
</code></pre>

<p>The output is same for both the functions. I am curious how string multiplication (first function) perform against for loop (second function) on performance basis. I mean which one is faster and mostly used?</p>

<p>Also please suggest me a way to get the answer to this question myself (using time.clock() or something like that)</p>
