这是代码:我无法将变量从整数转换成字符串
import time
import os
os.system("cls")
a=1
while True:
if a>512:
a=1
print (a + " kb")
if a<1024:
print (a + " bytes")
a *= 2
time.sleep(.5)
但它给我这个错误:
> Traceback (most recent call last):
> File "Sequence1.py", line 10, in <module>
> print (a + " bytes")
> TypeError: unsupported operand type(s) for +: 'int' and 'str'
如果我把它改成一个字符串,然后如果我声明不起作用。对不起,如果这个问题之前已经问过。谢谢。
'“{0} bytes”.format(a)'。 :/ – Amelia
链接下列网站可能很有用。 http://stackoverflow.com/questions/20441035/unsupported-operand-types-for-int-and-str – Jamescode0b