Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 589
Cycro the large planet Avatar asked Jul 21 '26 18:07

Cycro the large planet


1 Answers

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.

like image 166
Cycro the large planet Avatar answered Jul 24 '26 07:07

Cycro the large planet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!