我對這2個短代碼有兩個問題。python input()EOF錯誤和類型爲int的返回值?
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類型?我認爲所有的輸入都轉換爲字符串。
請請幫我理解這一點。這太痛苦了。
更改'輸入()''到的raw_input()'。它看起來像你在python 2中,無論你給'input'什麼都調用'eval'。 – roganjosh
[官方python2文檔](https://docs.python.org/2/library/functions.html#input ):「考慮將raw_input()函數用於用戶的一般輸入。」 – zypro