圆月山庄资源网 Design By www.vgjia.com

本文较为详细的介绍了python中raw_input的用法,使用raw_input 能够很方便的丛控制台读入数据。具体用法示例如下:

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)

2.输入整数

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

3.输入浮点型

fWeight = 0.0
fWeight = float(raw_input("input your weight\n"))
print 'your weight is %f' % fWeight

4.输入16进制数据

nHex = int(raw_input('input hex value(like 0x20):\n'),16)
print 'nHex = %x,nOct = %d\n' %(nHex,nHex)

5.输入8进制数据

nOct = int(raw_input('input oct value(like 020):\n'),8)
print 'nOct = %o,nDec = %d\n' % (nOct,nOct)

本文示例对Python初学者有一定的学习借鉴价值,感兴趣的读者可以动手调试运行一下本文示例,以加深对raw_input用法的认识。

标签:
Python,raw_input

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com