Exercise 3: Numbers And Math

来源:互联网 发布:野村周平水原希子 知乎 编辑:程序博客网 时间:2024/05/16 12:26

python天然支持数字和数学运算。在Exercise 0启动python时,它已经提供了一个计算器环境

>>> 25 + 3055>>> 55 / 69>>> 100 - 2575>>> 75 * 3 % 41

在这一章,列出了所有的数字操作符:

  • + (plus) does addition
  • - (minus) does subtraction
  • / (slash) does division
  • * (asterisk) does multiplication
  • % (percent) does modulus
  • < less-than
  • > greater-than
  • <= less-than-equal
  • >= greater-than-equal
注意到上面到代码,所有的数字都是整数,所以计算结果并不精确。可以将整数替换成小数

>>> 55.0 / 69.166666666666666


原创粉丝点击