python 2.x版本中才有内置函数raw_input和input两个函数;
python 3.x版本中并没有内置函数raw_input,如果在python 3.x版本中使用内置函数raw_input,会提示:NameError: name ‘raw_input’ is not defined
input返回的是数值类型,如int,float
raw_inpout返回的是字符串类型,string类型
input会计算在字符串中的数字表达式,而raw_input不会。
如输入 “57 + 3”:input会得到整数60;raw_input会得到字符串”57 + 3”;
看python input的文档,可以看到input其实是通过raw_input来实现的,原理很简单,就下面一行代码:
def input(prompt):
return (eval(raw_input(prompt)))
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有