Python讀取輸入值相關(guān)應(yīng)用技巧分享
Python編程語言中有一種應(yīng)用可以對輸入值進行讀取,這一應(yīng)用在實際操作中是非常重要的應(yīng)用技術(shù)。在這里,我們將會為大家詳細介紹一下有關(guān)Python讀取輸入值的相關(guān)應(yīng)用技巧,希望可以給大家?guī)硇椭?/p>
下面介紹了python raw_input的用法,使用raw_input 能夠很方便的叢控制臺讀入數(shù)據(jù)。
Python讀取輸入值操作方法1.輸入字符串
- #13222319810101****
- nID = ''
- while 1:
- nID = raw_input("Input your id plz")
- if len(nID) != len("13222319810101****"):
- print 'wring length of id,input again'
- else:
- break
- print 'your id is %s' % (nID)
Python讀取輸入值操作方法2.輸入整數(shù)
- nAge = int(raw_input("input your age plz:\n"))
- if nAge > 0 and nAge < 120:
- print 'thanks!'
- else:
- print 'bad age'
- print 'your age is %d\n' % nAge
Python讀取輸入值操作方法3.輸入浮點型
- fWeight = 0.0
- fWeight = float(raw_input("input your weight\n"))
- print 'your weight is %f' % fWeight
Python讀取輸入值操作方法4.輸入16進制數(shù)據(jù)
- nHex = int(raw_input('input hex value(like 0x20):\n'),16)
- print 'nHex = %x,nOct = %d\n' %(nHex,nHex)
Python讀取輸入值操作方法5.輸入8進制數(shù)據(jù)
- nOct = int(raw_input('input oct value(like 020):\n'),8)
- print 'nOct = %o,nDec = %d\n' % (nOct,nOct)
【編輯推薦】