输入函数input()和raw_input()的区别
2016-07-19 18:50
302 查看
raw_input_A = raw_input("raw_input DIGIT: ") print raw_input_A input_B =input("input DIGIT: ") print input_B print "INPUT :3 + %d = %d" % (input_B,input_B+3) print "RAW_INPUT :3 + %d = %d" % (raw_input_A,raw_input_A+3)
input()函数支持用户输入数字或者表达式,不支持输入字符串.返回的是数字类型的数值.
raw_input()函数捕获的是用户的原始输入,返回为字符串.如果需要用输入的数字计算,则需要使用int()函数转换一下.如果我们直接用输入的数值与某数想加,那么解释器就会报错:
TypeError: cannot concatenate ‘str’ and ‘int’ objects
输出结果:
raw_input DIGIT: 34 34 input DIGIT: 34 34 INPUT :3 + 34 = 37 Traceback (most recent call last): File "ex11.py", line 20, in <module> print "RAW_INPUT :3 + %d = %d" % (raw_input_A,raw_input_A+3) TypeError: cannot concatenate 'str' and 'int' objects
相关文章推荐
- apache thrift
- 1.如何避免野指针2.获取字符串的两种方法。以及malloc,calloc,ralloc的使用注意点3.二维三维数组4.数组和函数的区别
- shell 脚本攻略-find 文件查找总结
- EM算法与高斯混合聚类
- Linux进程间通信——使用信号量
- 移动Web开发规范概述
- php环境配置
- Android Studio更新gradle
- C语言之宏
- 毕淑敏:接纳自卑,感悟幸福
- 百度地图定位经纬度返回4.9E-324有关问题
- 薛之谦首唱会座无虚席 新歌全球首唱嗨爆全场
- 程序打开资源出错,原因为oracle密码过期
- 基于docker swarm和docker-compose搭建相异宿主机上的mysql和tomcat容器
- Apache服务器解压版配置(win版)
- [置顶] Linux_ubuntu&windows双系统grub引导修复
- Linux进程间通信——使用共享内存
- arm逆向工程abi
- 应用程序是如何去访问所需的硬件资源的?
- Android ImageCache ??