请教!关于Python!

没有结实的基础
请教下各位
在Python中查看cpu内存时怎么由字节转换成GB显示呀?


def size_to_nick(size) -> str:
    units=['B', 'KB', 'MB', 'GB', 'TB', 'PB']
    for i in range(len(units)):
        if pow(1024, i) <= size < pow(1024, i+1):
            return F'{size / pow(1024, i):.2f} {units[i]}'