当前位置:Gxlcms > Python > python里//什么意思

python里//什么意思

时间:2021-07-01 10:21:17 帮助过:133人阅读

python里//什么意思?

python里//表示取整除,返回商的整数部分(向下取整)

  1. #!/usr/bin/python#
  2. -*- coding: UTF-8 -*-
  3. a = 10
  4. b = 5
  5. c = a//b
  6. print "c 的值为:", c

输出:

  1. c 的值为: 2

注意:

Python2.x 里,整数除整数,只能得出整数。如果要得到小数部分,把其中一个数改成浮点数即可。

  1. >>> 1/2
  2. 0
  3. >>> 1.0/2
  4. 0.5
  5. >>> 1/float(2)
  6. 0.5

相关推荐:《Python教程》

以上就是python里//什么意思的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行