I have the following code which uses old style string formatting (this is not a modulo operation)
'b0%04x%02x' % (0, 0x0a)
which results in:
b000000a
Can someone explain what is happening here?
I have the following code which uses old style string formatting (this is not a modulo operation)
'b0%04x%02x' % (0, 0x0a)
which results in:
b000000a
Can someone explain what is happening here?
This is "old stye" string formatting. It replaces each format specifier (starting with %
in the string) with a formatted value of an argument in the tuple.
In your example:
fmt string output description
-------------------------------------------------------------------------------
b0 -> b0 - not a format specifier, output as literal characters
%04x -> 0000 - 4-digit hex representation of the first value in tuple
%02x -> 0a - 2-digit hex representation of the second value