用法:
hex([sep[, bytes_per_sep]])
返回一個字符串對象,其中包含實例中每個字節的兩個十六進製數字。
>>> b'\xf0\xf1\xf2'.hex() 'f0f1f2'
如果要使十六進製字符串更易於閱讀,可以指定單個字符分隔符
sep
參數以包含在輸出中。默認情況下,每個字節之間。第二個可選的bytes_per_sep
參數控製間距。正值從右側計算分隔符位置,負值從左側計算。>>> value = b'\xf0\xf1\xf2' >>> value.hex('-') 'f0-f1-f2' >>> value.hex('_', 2) 'f0_f1f2' >>> b'UUDDLRLRAB'.hex(' ', -4) '55554444 4c524c52 4142'
3.5 版中的新函數。
在 3.8 版中更改:bytes.hex現在支持可選
sep
和bytes_per_sep
用於在十六進製輸出中的字節之間插入分隔符的參數。
相關用法
- Python bytes.isupper用法及代碼示例
- Python bytes.zfill用法及代碼示例
- Python bytes.isalpha用法及代碼示例
- Python bytes.title用法及代碼示例
- Python bytes.isalnum用法及代碼示例
- Python bytes.removesuffix用法及代碼示例
- Python bytes.split用法及代碼示例
- Python bytes.lstrip用法及代碼示例
- Python bytes.expandtabs用法及代碼示例
- Python bytes.splitlines用法及代碼示例
- Python bytes.rstrip用法及代碼示例
- Python bytes.isdigit用法及代碼示例
- Python bytes.istitle用法及代碼示例
- Python bytes.removeprefix用法及代碼示例
- Python bytes.strip用法及代碼示例
- Python bytes.islower用法及代碼示例
- Python bytes()用法及代碼示例
- Python bytearray()用法及代碼示例
- Python binascii.crc32用法及代碼示例
- Python base64.b64decode()用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 bytes.hex。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。