string substitution in python - unsupported operand type(s) for %: 'list' and 'str' -


i'm stuck simple piece of code, i'm sure it's silly mistake, hope can point out me. here code have:

a = ['_a','_b','_c'] data_template = ['data%s'] f in a:     this_data = data_template % (f)     print this_data 

i want print out

data_a data_b data_c 

but following error:

typeerror: unsupported operand type(s) %: 'list' , 'str' 

any advice appreciated!

you need use string template: data_template = 'data%s'

the % operator works on strings, not on lists.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -