資訊內(nèi)容
python中int的用法是什么
python中int的用法:【int()】函數(shù)用于將一個字符串或數(shù)字轉(zhuǎn)換為整型,語法為【class int(x, base=10)】,參數(shù)x表示字符串或數(shù)字,base表示進(jìn)制數(shù),默認(rèn)十進(jìn)制。awT少兒編程網(wǎng)-https://www.pxcodes.com
awT少兒編程網(wǎng)-https://www.pxcodes.com
本教程操作環(huán)境:windows7系統(tǒng)、python3.9版,DELL G3電腦,該方法適用于所有品牌電腦。awT少兒編程網(wǎng)-https://www.pxcodes.com
python中int的用法:awT少兒編程網(wǎng)-https://www.pxcodes.com
描述awT少兒編程網(wǎng)-https://www.pxcodes.com
int() 函數(shù)用于將一個字符串或數(shù)字轉(zhuǎn)換為整型。awT少兒編程網(wǎng)-https://www.pxcodes.com
語法awT少兒編程網(wǎng)-https://www.pxcodes.com
以下是 int() 方法的語法:awT少兒編程網(wǎng)-https://www.pxcodes.com
class int(x, base=10)參數(shù)awT少兒編程網(wǎng)-https://www.pxcodes.com
x -- 字符串或數(shù)字。awT少兒編程網(wǎng)-https://www.pxcodes.com
base -- 進(jìn)制數(shù),默認(rèn)十進(jìn)制。awT少兒編程網(wǎng)-https://www.pxcodes.com
返回值awT少兒編程網(wǎng)-https://www.pxcodes.com
返回整型數(shù)據(jù)。awT少兒編程網(wǎng)-https://www.pxcodes.com
實(shí)例awT少兒編程網(wǎng)-https://www.pxcodes.com
以下展示了使用 int() 方法的實(shí)例:awT少兒編程網(wǎng)-https://www.pxcodes.com
>>>int() # 不傳入?yún)?shù)時,得到結(jié)果0 0 >>> int(3) 3 >>> int(3.6) 3 >>> int('12',16) # 如果是帶參數(shù)base的話,12要以字符串的形式進(jìn)行輸入,12 為 16進(jìn)制 18 >>> int('0xa',16) 10 >>> int('10',8) 8相關(guān)免費(fèi)學(xué)習(xí)推薦:python視頻教程awT少兒編程網(wǎng)-https://www.pxcodes.com
以上就是python中int的用法是什么的詳細(xì)內(nèi)容,更多請關(guān)注少兒編程網(wǎng)其它相關(guān)文章!awT少兒編程網(wǎng)-https://www.pxcodes.com

- 上一篇
python怎么判斷是否為字符串
簡介在python中可以使用isinstance()函數(shù)來判斷是否為字符串,語法格式“isinstance(object,basestring)”;isinstance()函數(shù)是用于判斷一個對象是否是一個已知的類型。本教程操作環(huán)境:windows7系統(tǒng)、python3版,DELLG3電腦python判斷
- 下一篇
python中怎么將列表的數(shù)據(jù)清空
簡介python中將列表數(shù)據(jù)清空的方法:1、使用del關(guān)鍵字,語法格式“dellist[:]”;2、使用clear()方法,該方法用于從列表中刪除所有元素,語法格式“l(fā)ist.clear()”。本教程操作環(huán)境:windows7系統(tǒng)、python3版,DELLG3電腦python中將列表數(shù)據(jù)清空的方法1、