跟着别人的代码试的,结果报错了,如下
TypeError: not all arguments converted during string formatting
i=10
print('hello' % str(i))
print('hello', str(i))
print(f'hello{str(i)}')
print('hello {}'.format(str(i)))
是不是 print('hello' , str(i))
i=10
print('hello%s'%str(i))
print('hello%d'%i)
更多可以参考这篇博客:https://blog.csdn.net/sinat_28576553/article/details/81154912
hello 后面要加个%s 占位符,不然程序不知道你后面的str(i)要赋值给谁。
'hello %s' % str(i)
我没看懂你的百分号,你是想格式化字符串吗?如果是格式化字符串,前面的字符串内应该对应相应的%➕字母,