Search code examples
pythonf-string

What does '!a' do in python f-strings?


When messing around in python with the exclamation mark, it said that it has to be followed by either !a, !s, or !r.
What does !a do?

Like can you do this?

f"{"txt"!a}"

What will be the result?

"TXT" # Obviously not this, but still

Solution

  • Found the answer to my question in the accepted answer for this question:

    !r (repr), !s (str) and !a (ascii) were kept around just to ease compatibility with the str.format alternative, you don't need to use them with f-strings.