Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我的变量没有变成字符串。。。为什么?_Python_String_Python 3.x_Concatenation - Fatal编程技术网

Python 我的变量没有变成字符串。。。为什么?

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,

我正在练习从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, 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哦,是的,我忘了它不是字符串。谢谢你的帮助!