例子:
val = 'test'
str1 = f'str1 is {val}'
str2 = f'str2 is {val!s}'
str3 = f'str3 is {val!r}'
print(str1)
print(str2)
print(str3)
# output
# str1 is test
# str2 is test
# str3 is 'test'
可以看出!s不带引号,!r带引号(默认单引号)
其实,!s相当于str(val)
!r相当于repr(val)
print(str('test'))
print(repr('test'))
#output
# test
# 'test'
具体参考Python Dunder/Magic Methods 魔法方法之