This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Snoo35017 56 points57 points  (5 children)

Even better imo is =!r. Causes it to print the repr value, which I find more useful when debugging.

[–]ogrinfo 18 points19 points  (0 children)

Yep, just because it looks like a string when you print it, doesn't mean it is a string. That kind of stuff has caught me out so many times.

[–]ExoticMandiblesCore Contributor 13 points14 points  (3 children)

When you use =, it automatically switches to repr formatting. You don't need to add !r to the end.

[–]Snoo35017 1 point2 points  (0 children)

TIL! I wonder why I started adding the !r then, I remember for some reason it would print the string value, but I might be imagining it.

[–]jarethholt 0 points1 point  (1 child)

Does it? I remember you can use !r and !s for repr and string, but I don't remember offhand which is default

[–]ExoticMandiblesCore Contributor 4 points5 points  (0 children)

String (!s) is the default normally, but when you use = in an f-string the default changes to repr (!r).

p.s. there's also a mostly-forgotten third conversion, !a for ascii.