0

I have a string like this: '{}, {space}'. Where I want to add/impute only the first value without touching the second ({space}) one.

But when i am doing like this: '{}, {space}'.format(1), this is giving me error like: KeyError: 'space'.

Please help.

Heisenberg
  • 79
  • 1
  • 4
  • 2
    Can you pre-double the braces? `'{}, {{space}}'.format(1)` will return `'1, {space}'` (filling in the undoubled placeholder and dedoubling the braces for the other). Somewhat sillier (but not requiring modifying the format string) would be to do: `'{}, {space}'.format(1, space='{space}')` – ShadowRanger May 17 '22 at 15:28
  • Does this answer your question? [How do I print curly-brace characters in a string while using .format?](https://stackoverflow.com/questions/5466451/how-do-i-print-curly-brace-characters-in-a-string-while-using-format) – Vulwsztyn May 17 '22 at 15:29

1 Answers1

0

Are you looking for something like this? Putting double brackets makes the {space} be ignored

print('{}, {{space}}'.format(1))

Output:

1, {space}
PurpleHacker
  • 358
  • 2
  • 9