通过计算 def calc(value): result = [] while value: result.append(value % 10) value = value // 10 #逆序,按正常的顺序返回 result.reverse() return result 通过自带方法 def method(value): #divmod()是内置函数,返回整商和余数组成的元组 result = [] while value: value, r = divmod(value, 10) resul
目标 想要获取一个整形数字的二进制表示 bin 内置函数 看一下官方的解释 Convert an integer number to a binary string prefixed with "0b". The result is a valid Python expression. If x is not a Python int object, it has to define an index() method that returns an integer. Some exa
#coding=utf- from struct import pack,unpack byte=pack('f',1.5) print(byte) print([i for i in byte]) byte=pack('f',123432.523424) print(byte) print([i for i in byte]) 输出 ?? ['\x00', '\x00', '\xc0', '?'] C?G ['C', '\x14', '\xf1', 'G']