Error “Can't convert 'int' object to str implicitly”
本问题已经有最佳答案,请猛点这里访问。
我刚开始自动化这些无聊的东西,我在第一章。
1 2 3 4 | myname = input() print ('It is nice to meet you,' + myname) lengthofname = len(myname) print ('your name is this many letters:' + lengthofname) |
我运行这个,它给了我
为什么这是一种错误的编码方式?
当您使用
有三种方法可以解决这个问题。
您有问题,因为
1 | print('your name is this many letters:' + str(lengthofname)) |
号
但是,您可以运行
1 | print('your name is this many letters:', lengthofname) |
你只记得
您的代码似乎是python 3.x。下面是正确的代码;只需在
1 2 3 4 | myname = input() print ('It is nice to meet you,' + myname) lengthofname = len(myname) print ('your name is this many letters:' + str(lengthofname)) |