1.使用內(nèi)置函數(shù) int 可以將其他類型數(shù)據(jù)轉(zhuǎn)換成整數(shù)
a='31'? ? ? # 數(shù)據(jù)類型 為str 字符串
print(a + 1)? #會(huì)報(bào)錯(cuò) 字符串 不可以和整數(shù) 做加法運(yùn)算
print(type(a))? # 31
b=int(a +1)? ? # 字符串轉(zhuǎn)換成 整數(shù) 可以做加法運(yùn)算
2.八進(jìn)制、十六進(jìn)制 整數(shù)
b='32'
o=int(b,8)? #字符串轉(zhuǎn) 八進(jìn)制整數(shù)
print(o)? # 26
c=int(b,16)? # 字符串轉(zhuǎn) 十六進(jìn)制整數(shù)
print(c)? # 50
print(bin(c))? #十六進(jìn)制整數(shù)轉(zhuǎn) 2進(jìn)制
0b110010