input(): 要求输入合法的python表达式, 例如字串需要加"", 四则运算会自动计算.

raw_input():所有输入视作字串

>>> val=input("input your expression: ")
input your expression: "what is your name"
>>> print "your input value is: "+val
your input value is: what is your name

>>> val=input("input your expression: ")
input your expression: 3*4+5
>>> print "your input value is: "+str(val)
your input value is: 17

注意: python中的"+"只能连接2个字串,或者作加号. 其它类型必须先转换...否则:

>>> print "your input value is: "+val
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects

python之input(), raw_input()的更多相关文章

  1. python使用input()来接受字符串时一直报错“xxx is not defined”

    报错信息: “Please input your guess: gussTraceback (most recent call last):  File "coinGuessGame.py& ...

  2. Python - 3. Input and Output

    from:http://interactivepython.org/courselib/static/pythonds/Introduction/InputandOutput.html Input a ...

  3. qpython 读入数据问题: EOF error with input / raw_input

    直接使用input会报错 EOF error with input / raw_input 原因是在qpy里console mode 命令行模式不是完全和pc上的命令行一致,所以input和raw_i ...

  4. 【Python笔记】2020年7月30日练习【python用input函数输入一个列表】

    练习课题链接:廖雪峰-Python教程-高级特性-迭代 学习记录: 1.Python当中类似于 三目运算符 的应用 2.Python用input函数输入一个列表 代码实例:对用户输入的一组数字转化成l ...

  5. python 中 input 和 raw_input 的区别

    input会假设输入的信息是合法的python表达式,例如,输入一个人名,Diesel,input会认为这是一个变量,必须加上引号,比如“Diesel”: 而raw_input会把所有的输入当作原始数 ...

  6. python中input()和raw_input()的区别

    两者均是python的内置函数,通过读取控制台的输入与用户实现交互.raw_input:将所有输入作为字符串看待,不管用户输入什么类型的都会转变成字符串.                   raw的 ...

  7. python中input和raw_input函数

    python input() 相等于 eval(raw_input(prompt)) ,用来获取控制台的输入. raw_input() 将所有输入作为字符串看待,返回字符串类型.而 input() 在 ...

  8. Python中的raw_input()和input()

    raw_input()和input()都是python中的内建函数,用于读取控制台用户的输入,但有所区别: [nr@localhost conf]$ python Python 2.7.5 (defa ...

  9. python中input()与raw_input()的区别到底是啥?-----marsggbo原创作品为你解答

    首先先给出总结:input () = int(raw_input()) 有图有真相!!! 先看看input的例子: 可见用input键入得到int类型的数据,那如果输入一些非int类型的会怎么样呢? ...

随机推荐

  1. cxGrid使用汇总2

    17. 怎样设计多表头的cxGrid? 解决:cxGrid可以解决如下的表头: --------------------------------- | 说明1 | 说明2 | ------------ ...

  2. jQuery选择器之层次选择器Demo

    测试代码: 02-层次选择器.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...

  3. hdu-5686 Problem B(斐波那契数列)

    题目链接: Problem B Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others) ...

  4. duplicate symbol _OBJC_METACLASS_$ 报错记录

    duplicate symbol _OBJC_METACLASS_$_TabbarButton in: /Users/hw201406/Library/Developer/Xcode/DerivedD ...

  5. Table of Contents - ActiveMQ

    Getting Started ActiveMQ 的安装 Hello World Configuring Standard ActiveMQ Components Connecting to Acti ...

  6. 纯css3 transforms 3D文字翻开翻转3D开放式效果

    详细内容请点击 在线预览立即下载 在本教程中,将基于CSS3创建的一个实现一个有趣的3D开放式效果.教程的目的是展示我们如何能带来一些生活上使用CSS3 . html: <ul class=&q ...

  7. vs2013发布时: sgen.exe 已退出 代码为 1

    出现这个错的时候,有查网上的.自己也亲试了一下,注意两个地方就行. 红色框里设成这样的值就OK了!

  8. Asp.Net-创建网站的快捷方式到桌面,开始菜单,收藏夹

            /// <summary>         /// 创建快捷方式         /// </summary>         /// <param na ...

  9. part 4 AngularJS ng src directive

  10. Part 34 to 35 Talking about multiple class inheritance in C#

    Part 34 Problems of multiple class inheritance Part 35 Multiple class inheritance using interfaces