我对这 2 个短代码有 2 个问题。
1.
name = input('what: ')
print(name)
输出
what: 641u
Traceback (most recent call last):
File "/Users/vuthynun/PycharmProjects/untitled1/h/__init__.py", line 1, in <module>
name = input('what: ')
File "<string>", line 1
641u
^
SyntaxError: unexpected EOF while parsing
Process finished with exit code 1
为什么会给我这个错误?
2.
name = input('what: ')
print(type(name))
输出:
what: 23
<type 'int'>
Process finished with exit code 0
为什么名字类型是int?我以为所有输入都转换为字符串。
请帮助我理解这一点。我快要死了。
请您参考如下方法:
在 python 2 中使用 raw_input 而不是 input。 这就是你获得字符串的方式。否则 python 将评估您提供的内容,这会给您带来意想不到的行为。
