标签:python raw_input input 读取输入 交互输入
函数:raw_input()和input()
>>> a1 = raw_input("raw_input_str: ")
raw_input_str: hello
>>> print a1,type(a1)
hello <type 'str'>
>>> a2 = input("input_str: ")
input_str: hello
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
a2 = input("input: ")
File "<string>", line 1, in <module>
NameError: name 'hello' is not defined
>>> a2 = input("input_str: ")
input_str: 'hello'
>>> print a2,type(a2)
hello <type 'str'>>>> b1 = raw_input("raw_input_int: ")
raw_input_int: 123
>>> print b1,type(b1)
123 <type 'str'>
>>> b2 = input("input_int: ")
input_int: 123
>>> print b2,type(b2)
123 <type 'int'>>>> c1 = raw_input("raw_input_exp: ")
raw_input_exp: 3 + 3
>>> print c1,type(c1)
3 + 3 <type 'str'>
>>> c2 = input("input_exp: ")
input_exp: 3 + 3
>>> print c2,type(c2)
6 <type 'int'>>>> d1 = raw_input("raw_input_sp: ")
raw_input_sp: \t
>>> print d1,type(d1)
\t <type 'str'>
>>> d2 = input("input_sp: ")
input_sp: \t
Traceback (most recent call last):
File "<pyshell#57>", line 1, in <module>
d2 = input("input_sp: ")
File "<string>", line 1
\t
^
SyntaxError: unexpected character after line continuation character
>>> d2 = input("input_sp: ")
input_sp: '\t'
>>> print d2,type(d2)
<type 'str'>Python raw_input()和input() 函数 读取交互输入
标签:python raw_input input 读取输入 交互输入
原文地址:http://blog.csdn.net/doiido/article/details/43575545