「python」hexメソッドで10進数を16進数に変換するサンプル

2020年12月12日

構文
hex(整数)

サンプルコード

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
# coding: utf-8
#!/usr/bin/python3
cftA = hex(255)
print("result1: ",cftA)
cftB = hex(-42)
print("result2: ",cftB)
cftC = hex(11)
print("result3: ",cftC)
# coding: utf-8 #!/usr/bin/python3 cftA = hex(255) print("result1: ",cftA) cftB = hex(-42) print("result2: ",cftB) cftC = hex(11) print("result3: ",cftC)
# coding: utf-8

#!/usr/bin/python3

cftA = hex(255)

print("result1: ",cftA) 

cftB = hex(-42)

print("result2: ",cftB) 

cftC = hex(11)

print("result3: ",cftC)

実行結果
>python test.py
result1: 0xff
result2: -0x2a
result3: 0xb

Python

Posted by arkgame