最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python內(nèi)置函數(shù)bin() oct()等實現(xiàn)進制轉(zhuǎn)換

 更新時間:2012年12月30日 16:27:50   作者:  
使用Python內(nèi)置函數(shù):bin()、oct()、int()、hex()可實現(xiàn)進制轉(zhuǎn)換;先看Python官方文檔中對這幾個內(nèi)置函數(shù)的描述,需要了解的朋友可以參考下
使用Python內(nèi)置函數(shù):bin()、oct()、int()、hex()可實現(xiàn)進制轉(zhuǎn)換。
先看Python官方文檔中對這幾個內(nèi)置函數(shù)的描述:
bin(x)
Convert an integer number to a binary string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer.
oct(x)
Convert an integer number to an octal string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer.
int([number | string[, base]])
Convert a number or string to an integer. If no arguments are given, return 0. If a number is given, return number.__int__(). Conversion of floating point numbers to integers truncates towards zero. A string must be a base-radix integer literal optionally preceded by ‘+' or ‘-‘ (with no space in between) and optionally surrounded by whitespace. A base-n literal consists of the digits 0 to n-1, with ‘a(chǎn)' to ‘z' (or ‘A' to ‘Z') having values 10 to 35. The default base is 10. The allowed values are 0 and 2-36. Base-2, -8, and -16 literals can be optionally prefixed with 0b/0B, 0o/0O, or 0x/0X, as with integer literals in code. Base 0 means to interpret exactly as a code literal, so that the actual base is 2, 8, 10, or 16, and so that int('010', 0) is not legal, while int('010') is, as well as int('010', 8).
hex(x)
Convert an integer number to a hexadecimal string. The result is a valid Python expression. If x is not a Python int object, it has to define an __index__() method that returns an integer.
2進制 8進制 10進制 16進制
2進制 - bin(int(x, 8)) bin(int(x, 10)) bin(int(x, 16))
8進制 oct(int(x, 2)) - oct(int(x, 10)) oct(int(x, 16))
10進制 int(x, 2) int(x, 8) - int(x, 16)
16進制 hex(int(x, 2)) hex(int(x, 8)) hex(int(x, 10)) -

bin()、oct()、hex()的返回值均為字符串,且分別帶有0b、0o、0x前綴。

相關(guān)文章

  • PyTorch搭建多項式回歸模型(三)

    PyTorch搭建多項式回歸模型(三)

    這篇文章主要為大家詳細介紹了PyTorch搭建多項式回歸模型,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-05-05
  • Python3讀取文件常用方法實例分析

    Python3讀取文件常用方法實例分析

    這篇文章主要介紹了Python3讀取文件常用方法,以實例形式較為詳細的分析了Python一次性讀取、逐行讀取及讀取文件一部分的實現(xiàn)技巧,需要的朋友可以參考下
    2015-05-05
  • pandas獲取對應(yīng)的行或者列方式

    pandas獲取對應(yīng)的行或者列方式

    這篇文章主要介紹了pandas獲取對應(yīng)的行或者列方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-02-02
  • Python如何將控制臺輸出另存為日志文件

    Python如何將控制臺輸出另存為日志文件

    這篇文章主要介紹了Python如何將控制臺輸出另存為日志文件問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-05-05
  • Python datatime庫語法使用詳解

    Python datatime庫語法使用詳解

    這篇文章主要介紹了Python datatime庫語法使用詳解,datetime模塊用于是date和time模塊的合集,文章圍繞相關(guān)資料展開詳情,感興趣的小伙伴可以擦參考一下
    2022-07-07
  • Python異步庫asyncio、aiohttp詳解

    Python異步庫asyncio、aiohttp詳解

    這篇文章主要介紹了Python異步庫asyncio、aiohttp使用,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-06-06
  • Python中sklearn實現(xiàn)交叉驗證示例分析

    Python中sklearn實現(xiàn)交叉驗證示例分析

    這篇文章主要介紹了Python中sklearn實現(xiàn)交叉驗證,本文python的版本為3.8,各個版本之間函數(shù)名字略有不同,但是原理都是一樣的,集成開發(fā)環(huán)境使用的是Anaconda的Spyder,需要的朋友可以參考下
    2023-08-08
  • Django--權(quán)限Permissions的例子

    Django--權(quán)限Permissions的例子

    今天小編就為大家分享一篇Django--權(quán)限Permissions的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-08-08
  • 在Python 2.7即將停止支持時,我們?yōu)槟銕砹艘环輕ython 3.x遷移指南

    在Python 2.7即將停止支持時,我們?yōu)槟銕砹艘环輕ython 3.x遷移指南

    這篇文章主要介紹了在Python 2.7即將停止支持時我們?yōu)槟銣蕚淞艘环輕ython 3.x遷移指南的相關(guān)資料,需要的朋友可以參考下
    2018-01-01
  • python粘包的解決方案

    python粘包的解決方案

    粘包就是在數(shù)據(jù)傳輸過程中有多個數(shù)據(jù)包被粘連在一起被發(fā)送或接受,本文主要介紹了python粘包的解決方案,具有一定的參考價值,感興趣的可以了解一下
    2024-01-01

最新評論

泾川县| 昭觉县| 井冈山市| 彰化县| 临安市| 菏泽市| 娱乐| 松江区| 紫阳县| 麦盖提县| 淮安市| 甘肃省| 剑川县| 闽侯县| 肥西县| 达尔| 普兰县| 凤凰县| 惠安县| 宜都市| 厦门市| 定日县| 宣恩县| 丹巴县| 台中市| 富源县| 盘山县| 安溪县| 镶黄旗| 罗定市| 灵台县| 新和县| 卫辉市| 商丘市| 房产| 仙居县| 龙门县| 高州市| 安岳县| 吴堡县| 长宁县|