国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁技術文章
文章詳情頁

Python字節單位轉換(將字節轉換為K M G T)

瀏覽:26日期:2022-06-26 16:03:13

def bytes_to_human(n): symbols = (’K’,’M’,’G’,’T’,’P’,’E’,’Z’,’Y’) prefix = {} for i,s in enumerate(symbols): prefix[s] = 1 << (i + 1) * 10 for s in reversed(symbols): if n >= prefix[s]: value = float(n) / prefix[s] return ’%.1f%s’ % (value,s) return ’%sB’ % npython編寫的儲存單位轉換代碼(以字節(B)為單位)

def bytes(bytes): if bytes < 1024: #比特 bytes = str(round(bytes, 2)) + ’ B’ #字節 elif bytes >= 1024 and bytes < 1024 * 1024: bytes = str(round(bytes / 1024, 2)) + ’ KB’ #千字節 elif bytes >= 1024 * 1024 and bytes < 1024 * 1024 * 1024: bytes = str(round(bytes / 1024 / 1024, 2)) + ’ MB’ #兆字節 elif bytes >= 1024 * 1024 * 1024 and bytes < 1024 * 1024 * 1024 * 1024: bytes = str(round(bytes / 1024 / 1024 / 1024, 2)) + ’ GB’ #千兆字節 elif bytes >= 1024 * 1024 * 1024 * 1024 and bytes < 1024 * 1024 * 1024 * 1024 * 1024: bytes = str(round(bytes / 1024 / 1024 / 1024 / 1024, 2)) + ’ TB’ #太字節 elif bytes >= 1024 * 1024 * 1024 * 1024 * 1024 and bytes < 1024 * 1024 * 1024 * 1024 * 1024 * 1024: bytes = str(round(bytes / 1024 / 1024 / 1024 / 1024 / 1024, 2)) + ’ PB’ #拍字節 elif bytes >= 1024 * 1024 * 1024 * 1024 * 1024 * 1024 and bytes < 1024 * 1024 * 1024 * 1024 * 1024 * 1024 * 1024: bytes = str(round(bytes / 1024 / 1024 / 1024 / 1024 / 1024 /1024, 2)) + ’ EB’ #艾字節 return bytes if __name__ == ’__main__’: print(’0:’ + bytes(0)) print(’1:’ + bytes(1)) print(’2:’ + bytes(10)) print(’3:’ + bytes(100)) print(’4:’ + bytes(1000)) print(’5:’ + bytes(10000)) print(’6:’ + bytes(100000)) print(’7:’ + bytes(1000000)) print(’8:’ + bytes(10000000)) print(’9:’ + bytes(100000000)) print(’10:’ + bytes(1000000000)) print(’11:’ + bytes(10000000000)) print(’12:’ + bytes(100000000000)) print(’13:’ + bytes(1000000000000)) print(’14:’ + bytes(10000000000000)) print(’15:’ + bytes(100000000000000)) print(’16:’ + bytes(1000000000000000)) print(’17:’ + bytes(10000000000000000)) print(’18:’ + bytes(100000000000000000)) print(’19:’ + bytes(1000000000000000000)) print(’20:’ + bytes(10000000000000000000)) print(’20:’ + bytes(100000000000000000000)) print(’20:’ + bytes(1000000000000000000000))

測試:

'D:Program FilesPythonPython36python.exe' C:/Users/Jochen/PycharmProjects/mysite/bytes.py0:0 B1:1 B2:10 B3:100 B4:1000 B5:9.77 KB6:97.66 KB7:976.56 KB8:9.54 MB9:95.37 MB10:953.67 MB11:9.31 GB12:93.13 GB13:931.32 GB14:9.09 TB15:90.95 TB16:909.49 TB17:8.88 PB18:88.82 PB19:888.18 PB20:8.67 EB20:86.74 EB20:867.36 EB

Process finished with exit code 0

到此這篇關于Python字節單位轉換(將字節轉換為K M G T)的文章就介紹到這了,更多相關Python字節單位轉換內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Python 編程
相關文章:
主站蜘蛛池模板: 国产欧美日本亚洲精品五区 | se94se欧美| 亚洲手机国产精品 | 亚洲一区二区三区四区在线 | 久久国产一片免费观看 | 亚洲 欧美 精品 | 国产成人精品本亚洲 | 国产高清自拍一区 | 在线a毛片免费视频观看 | 欧美另类久久久精品 | 日本欧美久久久久免费播放网 | 日本性色 | 成人毛片全部免费观看 | 国产一久久香蕉国产线看观看 | 日韩欧免费一区二区三区 | 97婷婷狠狠成人免费视频 | 成人午夜影视全部免费看 | 久久99精品视频在线在线观看 | 精品欧美一区二区三区免费观看 | 成人黄色毛片 | 国产日本欧美亚洲精品视 | 日本一级看片免费播放 | 成人爽a毛片在线视频 | 一级做a爱久久久久久久 | 国产欧美日韩在线观看一区二区三区 | 作爱在线观看 | 久色一区 | 河边性xxxxfreexxxxx | 国产精在线 | 91亚洲精品一区二区福利 | 偷柏自拍亚洲欧美综合在线图 | 欧美专区一区二区三区 | 97在线观看免费视频 | 精品久久久久久久久久香蕉 | 日本在线观看免费视频网址 | 亚洲高清在线观看播放 | 精品午夜国产在线观看不卡 | 欧美一级毛片在线一看 | 国产成人在线视频免费观看 | 欧美性毛片大片 | 国产日韩精品一区二区三区 |