将python中的一个float变量转成内存的4个字节值

#coding=utf-8
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])

输出

b'\x00\x00\xc0?'
[0, 0, 192, 63]
b'C\x14\xf1G'
[67, 20, 241, 71]

猜你喜欢

转载自www.cnblogs.com/sea-stream/p/10783217.html
今日推荐