hey guys, i want to perform the following operation:
b = 'random'
c = 'stuff'
a = '%s' + '%s' %(b, c)
but i get the following error:
TypeError: not all arguments converted during string formatting
does any one of you know to do so ?
Depending on what you want :
>>> b = 'random'
>>> c = 'stuff'
>>> a = '%s' %b + '%s' % c
>>> a
'randomstuff'
>>>
>>> b + c
'randomstuff'
>>>
>>> z = '%s + %s' % (b, c)
>>> z
'random + stuff'
>>>
+. Simple and clear.
%has a higher precedence than+so the compiler reads it as'%s' + ( '%s' % (b, c) )which fails as there is only one pattern for two values.a = ('%s' + '%s') % (b, c)also work? Because this seems to be just an operator precedence problem...('%s' + '%s')will combine into('%s%s'). Declaring('%s%s')is the same as'%s%s', so you end up with the same thing as'%s%s' % (b, c).