python - Inserting elements from array to the string -
i have 2 variables:
query = "string: {} number: {}" param = ['text', 1]
i need merge these 2 variables , keep quote marks in case of string , numbers without quote marks.
result= "string: 'text' number: 1"
i tried use query.format(param), removes quote marks around 'text'. how can solve that?
you can use repr
on each item in param
within generator expression, use format
add them string.
>>> query = "string: {} number: {}" >>> param = ['text', 1] >>> query.format(*(repr(i) in param)) "string: 'text' number: 1"
Comments
Post a Comment