首先先看单斜杆的用法:举几个例子

>>> print(5/3),type(5/3)
1.6666666666666667
(None, <class 'float'>)

>>> print(6/3),type(6/3)
2.0
(None, <class 'float'>)

>>> print 5.0/3,type(5.0/3)
1.66666666667 <type 'float'>
>>> print 5/3.0,type(5/3.0)
1.66666666667 <type 'float'>
>>> print 5.0/3.0,type(5.0/3.0)
1.66666666667 <type 'float'>

可以看出,无论数值是不是能整除,或者说A/B中A和B是不是int型,单斜杠的作用全是float型,结果是保留若干位的小数,是我们正常思维中的除法运算

在看看双斜杆的例子:

>>> print 5//3,type(5//3)
1 <type 'int'>
>>> print 5.0//3,type(5.0//3)
1.0 <type 'float'>
>>> print 5//3.0,type(5//3.0)
1.0 <type 'float'>
>>> print 5.0//3.0,type(5.0//3.0)
1.0 <type 'float'>
>>>

可以看出,在A//B的返回类型取决与A和B的数据类型,只有A和B都为int型时结果才是int(此时表示两数正除取商)

//取的是结果的最小整数,而/取得是实际的除法结果,这就是二者的主要区别啦

最新文章

  1. geotrellis使用(十五)使用Bokeh进行栅格数据可视化统计
  2. 高性能Web服务器Nginx的配置与部署研究系列(1)-- 入门 hello work
  3. sql修改约束语法练习
  4. Python包的相对导入时出现错误的解决方法
  5. memset函数具体说明
  6. 禁止选择文本和禁用右键 v1.0
  7. 在Sql Server 2005中将主子表关系的XML文档转换成主子表“Join”形式的表
  8. java--异常处理总结
  9. 使用VideoView开发视频总结
  10. ps修改图片文字
  11. Nginx启动错误:error while loading shared libraries: libpcre.so.1
  12. apscheduler -定时任务
  13. gitlab 灾备
  14. 升级mojave后的小问题解决
  15. set类型以及其操作
  16. Problem A: 零起点学算法80——逆序输出(数组练习)
  17. laravel的模板嵌套循环可以这样调试
  18. 27-THREE.JS 平面
  19. Python学习过程(一)
  20. appium python api(转)

热门文章

  1. 移动端适配(1)——viewport设置与初始化css
  2. node-sass 安装报错解决办法
  3. 修改Android系统关机动画
  4. ListView优化的时候ViewHolder的简洁写法
  5. Android触摸事件MotionEvent详解
  6. u-boot分析(六)----时钟初始化
  7. cocos2d-x滑动翻页,多出一点偏移量。
  8. wxWidgets窗口类型
  9. 如何在win10中安装ArcGIS10.2
  10. Android OpenGL ES 画球体