python中的 !r

python中的 指的是raw,即raw string 原始字符串,会忽略字符串中的所有转义字符。

!r 是一种字符串格式化方式,可以将任意对象转换成它的 repr() 表达形式,并将其嵌入到字符串中。

s1 = 'this is a string'

print(s1)
>> this is a string

print(f'{s1!r}')
>>  'this is a string'

print(repr(s1))
>>  'this is a string'

 

posted @ 2024-08-21 11:03  Liang-ml  阅读(1)  评论(0编辑  收藏  举报