Python magic function, how does it work? -
how magic function work (below) i.e. hex = '%032x' % self.int
reason turns following value...
265631021230191344138857284998518456
into....
0033289ed88646a64b9fc63c808fd6b8
def __str__(self): hex = '%032x' % self.int return hex
but should knowledge append 032x
end of string 265631021230191344138857284998518456
, whats going on? how does?
%x
format code hex. function representing decimal value in hex.
>>> hex(265631021230191344138857284998518456) '0x33289ed88646a64b9fc63c808fd6b8'
the full format code
'%032x'
means represent value in hex
, pad zeros on left until 32 characters wide.
Comments
Post a Comment