轉載:https://blog.csdn.net/a19990412/article/details/80149112
這兩個都是python的轉譯字符, 類似於%r, %d,%f
>>> a = '123'
>>> b = 'hello, {!r}'.format(a)
>>> b
"hello, '123'"
上面的例子用的是format,跟直接%效果類似。
>>> a = '123'
>>> b = 'hello, %r' % a
>>> b
"hello, '123'"
這對一部分的對象還是很有用的。r直接反應對象本體。
>>> a = '123'
>>> b = 'hello, %r' % a
>>> b
"hello, '123'"
123的本體就是123。
>>> b = 'hello, !r' % '123'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: not all arguments converted during string formatting
>>>
---------------------
!符號,這個只在fromat中有用,要注意方法。但是效果類似
>>> b = 'hello, %r' % '123'
>>> b
"hello, '123'"
>>> b = 'hello, {!r}'.format( '123')
>>> b
"hello, '123'"
更多操作有時間的話就去挖掘~
