views:

462

answers:

2

I want to print modulus operator as it is over the command line: E.g this is how the output should look like:
1%2
2%4

or
30%
40%

I am using the print statement like this:

print 'computing %s % %s' % (num1, num2)

Its throwing the default error:

TypeError: not all arguments converted during string formatting

For now I am using:

print 'computing 1'+'%'+'2'

which prints:

computing 1%2

But tell me how to get this done using the first approach(:print 'computing %s % %s' % (num1,num2))

+1  A: 
print 'computing %s %% %s' % (num1, num2)
truppo
+5  A: 

Escape the % sign with another % sign, like this:

print 'computing %s %% %s' % (num1, num2)
RexE
Documentation Reference: http://docs.python.org/library/stdtypes.html#string-formatting-operations
S.Lott