Search code examples
pythonpython-3.xf-string

Python3: f-string {} symbols screening


i want to use f-string in my python code to write some json, but got a problem with screening {} symbols. What the correct way to screen lonely { } symbols? For example i want to write:

data = f'{[{{prod_id},{quantity},{size}}]}'

I cant get how to write it correctly, and basic python screening not working for me for some reason here.


Solution

  • You can escape curly braces in f-strings by doubling them, e.g.

    data = f"{{[{{{prod_id},{quantity},{size}}}]}}"