more efficient?

Jean-Michel Pichavant jeanmichel at sequans.com
Tue Dec 22 07:54:50 EST 2009


Zubin Mithra wrote:
> I have the following two implementation techniques in mind.
>
> def myfunc(mystring):
>     check = "hello, there " + mystring + "!!!"
>     print check
>
>
> OR
> structure = ["hello, there",,"!!!"]
> def myfunc(mystring):
>     structure[2] = mystring
>     output = ''.join(mystring)
>
> i heard that string concatenation is very slow in python; so should i
> go for the second approach? could someone tell me why? Would there be
> another 'best-practice-style'?
> Please help. Thankx in advance!
>
> cheers!!!
> Zubin
>   
The best practice is to care more about your coding style (i.e. how you 
make your code easy to read & understand) than pointless speed optimization.
If you *really* care about speed, maybe you shoud use something else 
than python.

def myfunc(mystring):
    check = "hello, there %s !!!" % mystring
    print check

JM



More information about the Python-list mailing list