Python算术运算符实例详解
(编辑:jimmy 日期: 2024/11/20 浏览:3 次 )
Python算术运算符
以下假设变量a为10,变量b为20:
以下实例演示了Python所有算术运算符的操作:
#!/usr/bin/python a = 21 b = 10 c = 0 c = a + b print "Line 1 - Value of c is ", c c = a - b print "Line 2 - Value of c is ", c c = a * b print "Line 3 - Value of c is ", c c = a / b print "Line 4 - Value of c is ", c c = a % b print "Line 5 - Value of c is ", c a = 2 b = 3 c = a**b print "Line 6 - Value of c is ", c a = 10 b = 5 c = a//b print "Line 7 - Value of c is ", c
以上实例输出结果:
Line 1 - Value of c is 31 Line 2 - Value of c is 11 Line 3 - Value of c is 210 Line 4 - Value of c is 2 Line 5 - Value of c is 1 Line 6 - Value of c is 8 Line 7 - Value of c is 2
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
下一篇:老生常谈python函数参数的区别(必看篇)