编程语言
首页 > 编程语言> > 【Python】Python format

【Python】Python format

作者:互联网

"{0!r:20}".format("Hello")  
"{greeting!r:20}".format(greeting="Hello")  

r直接反应对象本体。

!符号,这个只在fromat中有用,要注意方法。但是效果类似

>>> b = 'hello, %r' % '123'
>>> b
"hello, '123'"
>>> b = 'hello, {!r}'.format( '123')
>>> b
"hello, '123'"

 

标签:20,format,Python,greeting,123,hello
来源: https://www.cnblogs.com/MilkAndPudding/p/16204255.html