我正在做一個練習問題,我需要從字符串中讀取輸入。如何讀取輸入()作爲Python中的字符串
person_age = 6
person_name = ''
person_name = input()
print('In 5 years', person_name, 'will be', person_age + 5) #not editable
但是,我得到的錯誤:TypeError: Can't convert 'int' object to str implicitly
我假設它這樣做是因爲PERSON_NAME已被解讀爲即使提供的字符串一個int。我怎樣才能得到這份工作?趕上是我不能編輯打印行。我只能在1聲明中代替person_name = input()
來做到這一點。我GOOGLE了它,看到,而不是使用的raw_input但功能不存在(也許是我對蟒蛇3)
你能複製並粘貼整個回溯而不只是'TypeError'行嗎? – rlee827
如果你沒有'raw_input',那麼你在Python 3上,'input'總是返回一個字符串。我只是在Python 2.7和3.5上運行你的代碼,並沒有給我一個錯誤。 – cco
沒有什麼趣事:'回溯(最近一次通話最後):文件「main.py」,第7行,在 print('5年後,person_name','person_age + 5) TypeError:Can not將'int'對象隱式轉換爲str' – dukevin