how to prepend string to a string?
Benji York
benji at benjiyork.com
Mon May 30 20:44:58 EDT 2005
flamesrock wrote:
> so I know you can append a string. But how do you *prepend* a string,
> as shown in the following code
>
> #dirList = ['depth1','depth2','depth3']
> #string = """position"""
> #for x in len(dirList):
> # string += '>> %s'%dirList.pop() #(????????????)
> #
How about string = whatever + string?
Note that recommended form is to build a list of strings and then use
''.join(all_my_strings) to form the final result.
After saying all that, here's a better way:
dirList = ['depth1','depth2','depth3', 'position']
print ' >> '.join(dirList)
--
Benji York
More information about the Python-list
mailing list