通过命令行打印 python 模数运算符
我想在命令行上打印模数运算符: 例如,输出应如下所示:
1%2
2%4
或
30%
40%
我正在使用这样的打印语句:
print '计算 %s % %s' % (num1, 编号2)
它抛出默认错误:
类型错误:并非所有参数 在字符串格式化期间转换
现在我正在使用:
打印'计算1'+'%'+'2'
打印:
计算1%2
但请告诉我如何使用第一种方法完成此操作(:print 'computing %s % %s' % (num1,num2))
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))
用另一个 % 符号转义 % 符号,如下所示:
Escape the % sign with another % sign, like this: