Python读取输入值相关应用技巧分享 - Go语言中文社区

Python读取输入值相关应用技巧分享


Python编程语言中有一种应用可以对输入值进行读取,这一应用在实际操作中是非常重要的应用技术。在这里,我们将会为大家详细介绍一下有关Python读取输入值的相关应用技巧,希望可以给大家带来些帮助。

下面介绍了python raw_input的用法,使用raw_input 能够很方便的丛控制台读入数据。

Python读取输入值操作方法1.输入字符串

  1. #13222319810101****  
  2. nID = '' 
  3. while 1:  
  4. nID = raw_input("Input your id plz")  
  5. if len(nID) != len("13222319810101****"):  
  6. print 'wring length of id,input again'  
  7. else:  
  8. break  
  9. print 'your id is %s' % (nID) 

Python读取输入值操作方法2.输入整数

  1. nAge = int(raw_input("input your age plz:n"))  
  2. if nAge > 0 and nAge < 120: 
  3. print 'thanks!'  
  4. else:  
  5. print 'bad age'  
  6. print 'your age is %dn' % nAge 

Python读取输入值操作方法3.输入浮点型

  1. fWeight = 0.0  
  2. fWeight = float(raw_input("input your weightn"))  
  3. print 'your weight is %f' % fWeight 

Python读取输入值操作方法4.输入16进制数据

  1. nHex = int(raw_input('input hex value(like 0x20):n'),16)  
  2. print 'nHex = %x,nOct = %dn' %(nHex,nHex) 

Python读取输入值操作方法5.输入8进制数据

  1. nOct = int(raw_input('input oct value(like 020):n'),8)  
  2. print 'nOct = %o,nDec = %dn' % (nOct,nOct) 

版权声明:本文来源51CTO,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:http://developer.51cto.com/art/201003/186469.htm
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2021-05-16 04:19:18
  • 阅读 ( 1025 )
  • 分类:Go应用

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢