var_a = 8
var_b = 3
var_c = "hello my name is:",var_a,"and",var_b,"bye"
print(var_c)
当我运行程序时,var_c 会像这样打印出来:('hello my name is:', 8, 'and', 3, 'bye') 但是所有的括号等也会被打印出来,为什么是这个和有没有办法摆脱这些符号?
如果我这样运行程序:
print("hello my name is:",var_a,"and",var_b,"bye")
我没有这个问题
最佳答案
您可以 format您的字符串以获得预期的字符串输出。
var_c = "hello my name is: {} and {}, bye".format(var_a, var_b)
如评论所述,您现有的输出是由于变量作为元组返回,而您希望它作为一个字符串。
关于python - 打印包含字符串和 2 个其他变量的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46119144/