print语句在python中表现得很奇怪

时间:2017-11-29 04:46:10

标签: python printing comma

当我编码时:

x = 4
y = 10

print("X is", x, "and Y is", y)

我得到了结果:

('X is', 4, 'and Y is', 10)

而不是:

X is 4 and Y is 10

为什么会这样?请帮忙。

1 个答案:

答案 0 :(得分:0)

用字符串格式化现代方法

print "x is {0} and y is {1}".format(x, y)

或旧学校

print "x is " + str(x) + " and y is " + str(y)

或使用

print("X is %d and Y is %d" % (x, y))