字符串格式

use*_*646 0 python string format

我不知道为什么结肠在第二次左转

>>> print '%5s' %':'
    :
>>> print '%5s' %':' '%2s' %':'
 : :
Run Code Online (Sandbox Code Playgroud)

请帮帮我

Gre*_*ill 9

在Python中,并置的字符串是连接在一起的:

>>> t = 'a' 'bcd'
>>> t
'abcd'
Run Code Online (Sandbox Code Playgroud)

所以在你的第二个例子中,它相当于:

>>> print '%5s' % ':%2s' % ':'
Run Code Online (Sandbox Code Playgroud)

根据Python的%运算符的优先规则,它是:

>>> print ('%5s' % ':%2s') % ':'
Run Code Online (Sandbox Code Playgroud)

要么

>>> print ' :%2s' % ':'
 : :
Run Code Online (Sandbox Code Playgroud)