![]()
这两个均是 python 的内建函数,通过读取控制台的输入与用户实现交互。但他们的功能不尽相同。举两个小例子。
1.输入为纯数字时
input返回的是数值类型,如int,float
raw_inpout返回的是字符串类型,string类型#!/usr/bin/python
# -*- coding: UTF-8 -*-
a = input('input:')
print 'type of input', type(a)
b = raw_input('raw_input:')
print 'type of raw_input', type(b)
输出:input:1
type of input
raw_input:1
type of raw_input
2.输入为计算公式时#!/usr/bin/python
# -*- coding: UTF-8 -*-
a = input('input:')
print a
b = raw_input('raw_input:')
print b
输出:input:1+2
3
raw_input:1+2
1+
3.输入为字符串时#!/usr/bin/python
# -*- coding: UTF-8 -*-
b = raw_input('raw_input:')
pri