Python TypeError:只能在数字循环中将str(而不是“int”连接到str
我正在尝试编写一个机器人来对Discord执行自动操作。为此,我编写了以下代码:Python TypeError:只能在数字循环中将str(而不是“int”连接到str,python,Python,我正在尝试编写一个机器人来对Discord执行自动操作。为此,我编写了以下代码: import clipboard import time numnum = input(" What do you want the delay from each next number? (in seconds) \n\t Please type it here: ") startingnum = input(" What do you want the sta
import clipboard
import time
numnum = input(" What do you want the delay from each next number? (in seconds) \n\t Please type it here: ")
startingnum = input(" What do you want the starting number to be? \n\t Please type it here: ")
for i in range startingnum , 99999999999999):
print('Your clip Board is set to ' + i )
clipboard.copy(i)
time.sleep(numnum)
print('terminal will close in 5 seconds')
time.sleep(5)
但是,此代码会生成以下错误:
TypeError: can only concatenate str (not "int") to str
我不知道为什么会发生这个错误,有人能告诉我为什么会在我的代码中发生这个错误吗?这是一个非常直接的语法问题 您正在尝试连接字符串
“您的剪贴板…”
和整数i
为了正确连接,请将整数类型转换为字符串
for i in range (startingnum , 100):
#typecast int --> str using the built in str() function
print('Your clip Board is set to ' + str(i) )
将i转换为字符串
import clipboard
import time
numnum = input(" What do you want the delay from each next number? (in seconds) \n\t Please type it here: ")
startingnum = input(" What do you want the starting number to be? \n\t Please type it here: ")
for i in range startingnum , 99999999999999):
print('Your clip Board is set to ' + str(i) )
clipboard.copy(i)
time.sleep(numnum)
print('terminal will close in 5 seconds')
time.sleep(5)
以下是您需要进行的两项更改:
import clipboard
import time
numnum = int(input(" What do you want the delay from each next number? (in seconds) \n\t Please type it here: ")) #Change 1
startingnum = int(input(" What do you want the starting number to be? \n\t Please type it here: "))
for i in range(startingnum , 99999999999999):
print('Your clip Board is set to ' , i ) #Change2
clipboard.copy(i)
time.sleep(numnum)
print('terminal will close in 5 seconds')
time.sleep(5)
TypeError:只能将str(而不是“int”)连接到str
您能解释一下这个句子中您不理解的特定单词吗?请删除问题中不必要的句子。并且清楚地告诉你错误发生的地方。当你在网上查找错误信息时,从你找到的许多参考资料中,你不明白什么?看到了吗
numnum = input(" What do you want the delay from each next number? (in seconds) \n\t Please type it here: ")
startingnum = input(" What do you want the starting number to be? \n\t Please type it here: ")
for i in range (startingnum , 99999999999999):
print('Your clip Board is set to ' + str(i) )
clipboard.copy(i)
time.sleep(numnum)
print('terminal will close in 5 seconds')
time.sleep(5)