0
return "{0!r}"
Hello all. Although I haven't really had much luck with getting questions answered I figured I'd try again. I recently came across the above code in a book I'm reading and am not too sure what it does... Anyone?
1 Answer
+ 2
"{0!r}" is a formatting string which must be used in conjunction with format(obj), where '0' means the first argo of format(), and '!r' is a modifier flag, which instruct to pass obj to __repr__() function.
In case of strings, used in place of obj, __repr__() is built-in and will render the string surrounded by single quotes.
So, for example,
print("{0!r}".format("sololearn"))
will simply output
'sololearn'