python string, best way to concat

Peter Otten __peter__ at web.de
Wed Aug 27 18:59:30 EDT 2014


Tim Chase wrote:

> On 2014-08-27 23:42, MRAB wrote:
>> How many parameters are there? len(self.param)
>> 
>> Make that many placeholders and then join them together with commas:
>> 
>> ', '.join(['?'] * len(self.param))
> 
> I prefer the clarity of Peter Otten's suggestion of
> 
>   ', '.join('?' * len(self.param))
> 
> over the mild obscurity of putting it in a list before multiplying.

As long as the OP doesn't try to transfer this to other paramstyles:

>>> ", ".join(["%s"]*3)
'%s, %s, %s'
>>> ", ".join("%s"*3) # OOPS
'%, s, %, s, %, s'





More information about the Python-list mailing list