Search code examples
pythonstringbracketsquotation-marks

How to remove quotation marks (and other marks)?


Is there any way to avoid printing out data (like quotations marks, brackets, commas and other important matematical symbols) when printing from a variable?

int1 = random.randint(1,100)
int2 = random.randint(1,100)
q1 = "What is", int1, "+", int2, "?"
answer = int(raw_input(q1))

The code above prints this:

('What is', 75, '+', 74, '? ')149

The proper way of printing the above would supposedly be this:

What is 75 + 74? 149

Solution

  • The clearest syntax I believe would be the one that separates the constant string from the variables:

    print "What is %d + %d?" % (int1, int2)