Reputation: 3
When I code:
x = 4
y = 10
print("X is", x, "and Y is", y)
I get as a result:
('X is', 4, 'and Y is', 10)
Instead of:
X is 4 and Y is 10
Why is this happening? Please help.
Upvotes: 0
Views: 344
Reputation: 25094
Just do it the modern way with string formatting
print "x is {0} and y is {1}".format(x, y)
Or old school
print "x is " + str(x) + " and y is " + str(y)
or use
print("X is %d and Y is %d" % (x, y))
Upvotes: 0
Reputation: 33310
You must be using python 2, where print
is a keyword instead of a function. It is interpreting the comma-separated items inside the parentheses as a tuple, and so it is printing the tuple.
Just remove the parentheses and it will work as you expect.
Upvotes: 2