Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在命令行上打印模运算符:例如,输出应该是这样的: 1%2 2%4
或 30% 40%
我正在使用这样的打印语句:
print '计算 %s % %s' % (num1, num2)
它抛出默认错误:
TypeError:字符串格式化期间并非所有参数都转换了
现在我正在使用:
打印'计算1'+'%'+'2'
打印:
计算 1%2
但是请告诉我如何使用第一种方法完成此操作(:print 'computing %s % %s' % (num1,num2))
用另一个 % 符号转义 % 符号,如下所示:
print 'computing %s %% %s' % (num1, num2)