从今天起开始自学python.
参考视频是edx平台上的UTAx: CSE1309x Introduction to Programming Using Python;参考书籍是:挪威的Magnus Lie Hetland所著的<
>>> a = input("input: ")
input: 12.2
>>> type(a)
<type 'float'>
>>> a = input("input: ")
input: 11
>>> type(a)
<type 'int'>
>>> a = input("input: ")
input: abv
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<string>", line 1, in <module>
NameError: name 'abv' is not defined
>>>
>>> a = input("input: ")
input: "a"
>>> type(a)
<type 'str'>
>>>
而raw_input则是把所有输入都当做原始数据(raw data),然后将其放入字符串中,比如输入的是整数,想要使用它的话,需要转换一下.
>>> a = raw_input("input: ")
input: 12
>>> print a*a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't multiply sequence by non-int of type 'str'
>>> print a
12
>>> print (int(a)*int(a))
144
>>>
以下是一篇比较好的关于input 和 raw_input 的文章
http://www.cnblogs.com/way_testlife/archive/2011/03/29/1999283.html
raw_input() 与 input() __ Python
这两个均是 python 的内建函数,通过读取控制台的输入与用户实现交互。但他们的功能不尽相同。举两个小例子。
复制代码
1 >>> raw_input_A = raw_input(“raw_input: “)
2 raw_input: abc
3 >>> input_A = input(“Input: “)
4 Input: abc
5
6 Traceback (most recent call last):
7 File “