您的位置:首页 > 编程语言 > Python开发

[基础] - Python中 raw_input 和 input 的区别

2015-11-25 14:17 495 查看

[基础] - Python中 raw_input 和 input 的区别

raw_input

不管用户输入什么类型的都会转变成字符串型。

input

根据用户输入变换相应的类型,如果要输入字符和字符串的时候必须要用引号包起来。

>>> raw_input_A = raw_input("raw_input: ")
raw_input: abc
>>> input_A = input("Input: ")
Input: abc
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
input_A = input("Input: ")
File "<string>", line 1, in <module>
NameError: name 'abc' is not defined
>>> input_A = input("Input: ")
Input: "abc"
>>>

>>> raw_input_B = raw_input("raw_input: ")
raw_input: 123
>>> type(raw_input_B)
<type 'str'>
>>> input_B = input("input: ")
input: 123
>>> type(input_B)
<type 'int'>


4000
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: