0

Is it possible in Python to have a single, unmatched curly brace in a format string? I know that I can use double matched braces to print a single matched brace but I can't express just a single brace without my intent being ambiguous.

'{{}} {}'.format(42) # Yields '{} 42' - this is not what I'm asking about
'{ %d' % 42 # Yields '{ 42' - this is what I want, but with the format syntax
'{{} {}'.format(42) # Not valid because the braces are unmatched
'\{ {}'.format(42) # Not valid because escaped brace characters are not supported

I fear that this ability does not exist in Python, but I would like confirmation. I suspect I will have to resort to using a different type of formater (the % syntax) or string concatenation.

JimPri
  • 1,278
  • 8
  • 17

0 Answers0