ADM-201 dump PMP dumps pdf SSCP exam materials CBAP exam sample questions

Python的除法及其他数学运算 – 译学馆
未登录,请登录后再发表信息
最新评论 (0)
播放视频

Python的除法及其他数学运算

Division with Python, and other math

如果你上手python 你会发现你能用python做基本的数学运算
So if you started with python, you found that you can do basic math within python.
它真的不难
It’s really not too difficult.
你可以计算 比如 7*8 输出结果是56
You can do things like 7 times 8. You put it out, it’s 56.
你可以计算 7-8 结果是 -1
You can do 7 minus 8. You get negative one.
你可以计算 7+8 结果是15
You can do 7 plus 8. You get 15.
然后当然是 7/8 结果是0
And then of course 7 divided by 8, and you get 0.
显然这有一个问题 python怎样处理小数部分的除法
Obviously this is a problem, so how to do division get decimals within python
很简单 这里主要有两种方式
It’s quite simply. There’s a couple of major ways to do this.
第一个就是简单地给数字加上小数部分
The first one is to just simply use decimals in your numbers.
这相当于告诉python说 嘿 我要做小数运算
This kind of notifies python to say “hey, I’d like to go to decimals”
所以你可以写成7.0除以
So you can say 7.0 divided by,
你可以这样写 8 它仍将会得到小数结果
you can do it this way 8 and it will still give you decimal numbers.
但最好的方法应该是两边都加上小数部分
But the best way to do it is probably to give decimals on both sides.
显然答案相同
Obviously same answer.
现在假如你不一定想要给它加上小数点
Now what if you don’t want to have to add the decimal point to it
或像是从另一个没有小数点的地方加上小数点
or like say your point from another source that’s not having the decimal point.
但你仍然要做除法
You still want to do division.
最简单的办法是让python知道你想要让所有的除法都变成那样
The easiest way to do that is to inform python that you want all the division to be this way.
为了做到这一点 在脚本的顶部 我会用IDLE向你展示
And to do that, at the very top of your script, I’ll actually show you guys within IDLE.
让我暂停一下 我会打开IDLE 告诉你输入的内容
So let me pause this really quick and I’ll open up IDLE to show you what you’ll type in there.
好 我们来到典型的python开发环境 它叫做IDLE
Right, here we are in the typical python IDE called IDLE.
你必须所要做的是 从“__future__”导入division
What you are going to have to do is use the from “__future__” import division.
为了做到这一点 你只要逐字输入 “from __future__ import division”
And to do that you just literally type that out “from __future__ import division”
现在所做的就是告诉Python你要使用这个模块
Now what this is doing is telling python that you want to use this module.
要像这样使用任何from __future__ import 你必须把它放在脚本的顶部
To use any from __future__ import like this, you have to put it at the top of your script.
甚至如果你导入其他的 它们必须放在任何from __future__ imports下面
Even if you have other imports, they must go below any from __future__ imports.
就这样继续
So continuing right along.
所有你要做的就是打印7除以8
All you have to do is just to tell it to print 7 divided by 8.
这里 保存它
Here, save it.
运行它
Run it.
你可以看到它打印出的内容 我们并未使用任何小数点
And as you can see it printed out, and we didn’t use any decimal points.
这些就是python里的除法了
So that’s division within python.

发表评论

译制信息
视频概述

Python教学系列,除法及其他数学运算。

听录译者

[B]hugue

翻译译者

B11101001

审核员

嘉言先森

视频来源

https://www.youtube.com/watch?v=vpIl6oszxAM

相关推荐