DAY2 raw_input() 与 input() Python
使用input和raw_input都可以读取控制台的输入,input()只能接受int,float或由它们组成的表达式:
Python 2.7.5 (default, Mar 19 2014, 07:24:16)
[GCC 4.5.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> input("input something: ")
input something: 123
123
>>> input("input something: ")
input something: abc
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'abc' is not defined
>>>
input和raw_input在处理数字时是有区别的:
1.输入为纯数字时
input返回的是数值类型,如int,float
raw_inpout返回的是字符串类型,string类型
print "how old are you?"
age1 = input()
print "%r" % age1
age2 = raw_input()
print "%r" % age2
返回结果:
how old are you?
22
22 22
'' //raw_input()把输入整形当做字符串处理
2.输入字符串为表达式
input会计算在字符串中的数字表达式,而raw_input不会。
sum = input()
print "%r" % sum
sum = raw_input()
print "%r" % sum
结果:
1+2
3 1+2
'1+2'
DAY2 raw_input() 与 input() Python的更多相关文章
- raw_input() 与 input() __ Python
这两个均是 python 的内建函数,通过读取控制台的输入与用户实现交互.但他们的功能不尽相同.举两个小例子. 1 >>> raw_input_A = raw_input(" ...
- python中raw_input() 与 input()
参考网址:http://www.cnblogs.com/way_testlife/archive/2011/03/29/1999283.html 在python中如何接收一个输入的字符串. 举个例子: ...
- python中raw_input()与input()
raw_input([prompt]) input([prompt]) # prompt:如果参数存在,直接输出到屏幕上,不会再另起一行 raw_input 如其字面意思一样,返回输入字符的字符串形式 ...
- Python raw_input和input总结 在版本2和版本3中的区别
Python 2.3.4 (#1, Feb 2 2005, 11:44:13) [GCC 3.4.3 20041212 (Red Hat 3.4.3-9.EL4)] on linux2 Type &q ...
- Python中的raw_input()和input()
raw_input()和input()都是python中的内建函数,用于读取控制台用户的输入,但有所区别: [nr@localhost conf]$ python Python 2.7.5 (defa ...
- Python 内置函数raw_input()和input()用法和区别
我们知道python接受输入的raw_input()和input() ,在python3 输入raw_input() 去掉乐,只要用input() 输入,input 可以接收一个Python表达式作为 ...
- raw_input() 与 input()
这两个均是 python 的内建函数,通过读取控制台的输入与用户实现交互.但他们的功能不尽相同. >>> raw_input_A = raw_input("raw_inpu ...
- raw_input() 与 input()的区别
raw_input和input两个均是 python 的内建函数,通过读取控制台的输入与用户实现交互.但他们的功能不尽相同.下面举两个例子,来说明两者 raw_input和input两个均是 pyth ...
- raw_input() 与 input()对比
转载来自http://www.cnblogs.com/way_testlife/archive/2011/03/29/1999283.html 这两个均是 python 的内建函数,通过读取控制台的输 ...
随机推荐
- HTML5学习总结-08 应用缓存(Application Cache)
一 应用缓存(Application Cache) 1 应用缓存 HTML5 引入了应用程序缓存,这意味着 web 应用可进行缓存,并可在没有因特网连接时进行访问. 应用程序缓存为应用带来三个优势: ...
- mysql support chinese
1.创建table的时候使用utf8编码 create table tablename ( id int NOT NULL, content var_char(250) NOT NULL, CON ...
- 阿里巴巴集团2016校园招聘-Python工程师笔试题(附加题+部分答案)
前言 第一次网上笔试,被虐的很惨.一是不太习惯,最主要的是还是自己对Python的掌握,还不够熟练.下面是这次阿里笔试相关信息 笔试时间是,2015年8月23日,10:00——12:00 对于笔试题, ...
- SQL Server 2012 学习笔记1
1. 新建的数据库会产生两个文件(数据文件.mdf 和日志文件.ldf) 2. 编辑表格和为表格录入数据 "Design"为设计表格,"Edit Top 200 Rows ...
- 获取字符串中每个字符出现的次数(利用TreeMap)
案例:"aababcabcdabcde",获取字符串中每一个字母出现的次数要求结果:a(5)b(4)c(3)d(2)e(1)分析1:定义一个字符串(可以改进为键盘录入)2:定义一个 ...
- eclipse安装springsource-tool-suite
到http://spring.io/tools/sts/all找到安装的eclipse对应的springsource-tool-suite版本,复制下载的网址 然后在eclipse的install n ...
- Android学习笔记——Handler(一)
使用Handler管理线程(转) 步骤: 1. 申请一个Handler对象 Handler handler = new Handler(); 2. 创建一个线程 {继承Thread类或者实现Runna ...
- 11 Clever Methods of Overfitting and how to avoid them
11 Clever Methods of Overfitting and how to avoid them Overfitting is the bane of Data Science in th ...
- codeforces 719A Vitya in the Countryside(序列判断趋势)
题目链接:http://codeforces.com/problemset/problem/719/A 题目大意: 题目给出了一个序列趋势 0 .1 .2 .3 ---14 .15 .14 ----3 ...
- CodeForces 716A Crazy Computer
题目链接:http://codeforces.com/problemset/problem/716/A 题目大意: 输入 n c, 第二行 n 个整数,c表示时间间隔 秒. 每个整数代表是第几秒.如果 ...