Reputation: 259
I think I understand what % means in python. But I don't understand what the 0x and 4x means. Any help is great even if you just link the documentation for %.
Here is the example code:
wr.write('Base Addr=0x%4x' %
(Base_Address))
Upvotes: 0
Views: 1269
Reputation: 310117
%4x
is a way of formatting a number in hexidecimal
>>> '%4x' % 0xffff
'ffff'
>>> '%4x' % 0xffa1
'ffa1'
The leading 0x
will just be literal characters that end up carrying over into the string.
>>> '0x%4x' % 0xffa1
'0xffa1'
The 4
specifies the minimum width (smaller output will be padded on the left with spaces):
>>> '%4x' % 0xff
' ff'
Upvotes: 5