I am not getting why the colon shifted left in the second time
>>> print '%5s' %':'
:
>>> print '%5s' %':' '%2s' %':'
: :
Help me out of this please
I am not getting why the colon shifted left in the second time
>>> print '%5s' %':'
:
>>> print '%5s' %':' '%2s' %':'
: :
Help me out of this please
What are you trying to do?
>>> print '%5s' % ':'
:
>>> print '%5s%2s' % (':', ':')
: :
You could achieve what you want by mixing them both into a single string formatting expression.
In Python, juxtaposed strings are concatenated:
>>> t = 'a' 'bcd'
>>> t
'abcd'
So in your second example, it is equivalent to:
>>> print '%5s' % ':%2s' % ':'
which by the precedence rules for Python's % operator, is:
>>> print ('%5s' % ':%2s') % ':'
or
>>> print ' :%2s' % ':'
: :