python中的除法
2015-11-18 00:00
573 查看
摘要: python中的除法
在python2.7中,两个整数相除的结果默认会保留整数,可以用from __future__ import division改变这种行为。
在python3中,默认行为发生了变化,如果要使用整数除,可以使用//
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 7/3
2
>>> 7/3.0
2.3333333333333335
>>> from __future__ import division
>>> 7/3
2.3333333333333335
>>> 7//3
2
>>>
在python2.7中,两个整数相除的结果默认会保留整数,可以用from __future__ import division改变这种行为。
在python3中,默认行为发生了变化,如果要使用整数除,可以使用//
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 7/3
2
>>> 7/3.0
2.3333333333333335
>>> from __future__ import division
>>> 7/3
2.3333333333333335
>>> 7//3
2
>>>
相关文章推荐
- Python3.4+Django1.7+SQLite3实现增删改查
- Python操作文件目录
- python中的三个读read(),readline()和readlines()
- lesson 2.4 - Converting MEL Commands to Python
- wxpython学习3
- Python、Unicode和中文
- <LeetCode><Easy>299 Bulls and Cows
- 新手学编程?选python吧!
- 文章标题
- python编码问题(1)
- Python——变量命名规则以及打印操作
- 爬虫 第三篇 (语言选择python还是java)
- 开启Python的学习路程
- python_1
- python语言综述
- Python基础学习-爬虫入门知识
- 基于Python的机器学习实战:AadBoost
- 关于python 科学计算库的下载
- Python学习(一)常用函数
- python中的文件操作