初识python

从今天起开始自学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 “

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值