我对这两个短代码有两个问题。
1.
name = input('what: ')
print(name)
output
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))
output:
what: 23
<type 'int'>
Process finished with exit code 0
为什么name类型是int?我以为所有输入都转换为字符串。
请帮助我理解这一点。这太痛苦了。
Use raw_input
代替input
在Python 2中。
这就是你获得字符串的方式。否则 python 会评估你给它的东西,这会给你带来意想不到的行为。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)