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

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -