python中int()函數(shù)用于將一個字符串或數(shù)字轉(zhuǎn)換為整型。
以下是int()方法的語法:
int(x,base=10)
參數(shù)
x--字符串或數(shù)字。
base--進制數(shù),默認十進制。
返回值
返回整型數(shù)據(jù)
實例
以下展示了使用int()方法的實例:
>>>int()#不傳入?yún)?shù)時,得到結(jié)果0
0
>>>int(3)
3
>>>int(3.6)
3
>>>int('12',16)#如果是帶參數(shù)base的話,12要以字符串的形式進行輸入,12為16進制
18
>>>int('0xa',16)
10
>>>int('10',8)
8
以上內(nèi)容為大家介紹了python培訓之int函數(shù)怎么用,希望對大家有所幫助,如果想要了解更多Python相關知識,請關注IT培訓機構(gòu):千鋒教育。