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

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

 更新時(shí)間:2012年12月30日 16:27:50   作者:  
使用Python內(nèi)置函數(shù):bin()、oct()、int()、hex()可實(shí)現(xiàn)進(jìn)制轉(zhuǎn)換;先看Python官方文檔中對(duì)這幾個(gè)內(nèi)置函數(shù)的描述,需要了解的朋友可以參考下
使用Python內(nèi)置函數(shù):bin()、oct()、int()、hex()可實(shí)現(xiàn)進(jìn)制轉(zhuǎn)換。
先看Python官方文檔中對(duì)這幾個(gè)內(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進(jìn)制 8進(jìn)制 10進(jìn)制 16進(jìn)制
2進(jìn)制 - bin(int(x, 8)) bin(int(x, 10)) bin(int(x, 16))
8進(jìn)制 oct(int(x, 2)) - oct(int(x, 10)) oct(int(x, 16))
10進(jìn)制 int(x, 2) int(x, 8) - int(x, 16)
16進(jìn)制 hex(int(x, 2)) hex(int(x, 8)) hex(int(x, 10)) -

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

相關(guān)文章

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

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

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

    Python3讀取文件常用方法實(shí)例分析

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

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

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

    Python如何將控制臺(tái)輸出另存為日志文件

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

    Python datatime庫(kù)語(yǔ)法使用詳解

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

    Python異步庫(kù)asyncio、aiohttp詳解

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

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

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

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

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

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

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

    python粘包的解決方案

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

最新評(píng)論

丽水市| 泗洪县| 句容市| 景东| 罗甸县| 宝坻区| 友谊县| 信宜市| 德昌县| 宁津县| 屏东县| 安岳县| 竹山县| 永胜县| 宜兴市| 永丰县| 墨玉县| 张家口市| 房山区| 三明市| 金溪县| 若羌县| 安溪县| 施秉县| 屏东县| 图们市| 津市市| 晴隆县| 临夏市| 五家渠市| 唐河县| 香港| 成安县| 图片| 陵川县| 柳林县| 南靖县| 梨树县| 藁城市| 昆明市| 济源市|