Python 我的变量没有变成字符串。。。为什么?
我正在练习从Codecademy+其他来源学到的东西。我正在尝试运行此代码(由于此错误而未完成): 但每次我尝试这样做时,都会出现以下错误:Python 我的变量没有变成字符串。。。为什么?,python,string,python-3.x,concatenation,Python,String,Python 3.x,Concatenation,我正在练习从Codecademy+其他来源学到的东西。我正在尝试运行此代码(由于此错误而未完成): 但每次我尝试这样做时,都会出现以下错误: word = input("What word do you want analyzed? ") word = str(word) print("word: " + word, "length of word" + len(word)) "length of word" + len(word)) TypeError: must be str,
word = input("What word do you want analyzed? ")
word = str(word)
print("word: " + word,
"length of word" + len(word))
"length of word" + len(word))
TypeError: must be str, not int
我做错了什么??我应该在len()方法中放一个str()方法吗
我应该在len()方法中放一个str()方法吗
不,在它之外
print("word: " + word,
"length of word" + str(len(word)))
len(string)return INT
,不能与string
len(string)
返回一个整数,你需要将它转换为字符串,因为str(len(word))
@SterlingArcher哦,是的,我忘了它不是字符串。谢谢你的帮助!