Python風格總結:十進制轉二進制、八進制、十六進制

Python 十進制轉二進制、八進制、十六進制

# -*- coding: UTF-8 -*-

# Filename : test.py
# author by : www.runoob.com

# 獲取用戶輸入十進制數
dec = int(input("輸入數字:"))

print("十進制數爲:", dec)
print("轉換爲二進制爲:", bin(dec))
print("轉換爲八進制爲:", oct(dec))
print("轉換爲十六進制爲:", hex(dec))

結果輸出:

輸入數字:15
十進制數爲: 15
轉換爲二進制爲: 0b1111
轉換爲八進制爲: 0o17
轉換爲十六進制爲: 0xf

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章