金点网络-全网资源,一网打尽
  • 网站首页
    • 金点部落
    • 小游戏
    • OpenAPI
    • 设计资产导航
    • 升级会员
  • 技能学习
    • 体育运动
    • 办公教程
    • 口才演讲
    • 小吃技术
    • 建站教程
    • 摄影教程
    • 棋牌教程
    • 网赚教程
      • 爆粉引流
      • 自媒体
      • 贴吧引流
  • 网站源码
    • 商城/淘客/交易
    • 小说/漫画/阅读
    • 影视/音乐/视频
    • 微信/微商/微擎
    • 理财/金融/货币
    • 模板/主题/插件
  • 游戏源码
    • 精品网单
    • 端游源码
    • 手游源码
    • 页游源码
  • 素材资料
    • 电子文档
    • 综合资料
    • 考研资料
    • 设计素材
    • 音频讲座
      • 人文艺术
      • 名师讲座
      • 说书小说
  • 软件工具
    • Windows软件
    • MacOS软件
    • Android软件
  • 寄售资源
    • 游戏源码
    • 网站源码
    • 软件源码
  • 公益服
登录/注册
  • 专享大神特权
立即开通开通会员抄底价

Python数据分析(中英对照)·Expressions and Booleans 表达式和布尔值

作者 : jamin 本文共5126个字,预计阅读时间需要13分钟 发布时间: 2020-10-18 共1067人阅读

1.1.6: Expressions and Booleans 表达式和布尔值

表达式是计算值的对象和运算符的组合。
Expression is a combination of objects and operators that computes a value.
许多表达式都涉及所谓的布尔数据类型。
Many expressions involve what is known as the boolean data type.
布尔类型的对象只有两个值。
Objects of the boolean type have only two values.
这些被称为真与假。
These are called True and False.
在Python中,您需要大写这些单词,True和False,以便Python将它们理解为布尔类型。
In Python, you need to capitalize these words, True and False,for Python to understand them as boolean type.
让我们很快检查一下。
Let’s just check very quickly.
如果我们键入True,Python会告诉我们这是一个布尔对象。
If we type True, Python tells us this is a boolean object.
或者如果我们问Python,False的类型是什么,F大写,Python告诉我们这是一个布尔对象。
Or if we ask Python, what is the type of False, with F capitalized,Python tells us this is a boolean object.
注意,如果我不大写false,Python就不知道这个对象是什么。
Note that if I don’t capitalize false, Python doesn’t know what this object is.
它不明白这一点。
It doesn’t understand that.
因此,您需要确保将布尔类型大写。
So you need to be sure to capitalize your boolean types.
涉及逻辑的操作,即所谓的布尔操作,接收一个或多个布尔对象,然后
Operations involving logic, so-called boolean operations,take in one or more boolean object and then
它们会将一个布尔对象返回给您。
they return one boolean object back to you.
只有三种布尔运算,即“或”、“与”和“非”。
There are only three boolean operations, which are "or", "and", and "not".
让我们试试这些。
So let’s try these out.
让我们从“或”开始。如果x为真或y为真,或者两者都为真,那么x和y之间的“或”将为真。
Let’s start with "or". "Or" between x and y is going to be True if either x is True or y is True, or both are True.
例如,如果我们说True或False,那么Python返回True。
So for example, if we say True or False, then Python returns True.
真或真也会是真的。
True or True would also be True.
所以唯一的时间“或”是假的——如果“或”周围的第一个和第二个对象都是假的。
So the only time "or" would be False– if both the first and second object surrounding "or" are False.
只有当两个对象都为真时,“And”才为真。
"And" is only true if both objects are True.
所以如果我们输入True和True,答案将是True。
So if we type True and True, the answer is going to be True.
然而,如果我们把第二个真的变成假,“和”将是假的。
However, if we turned the second True to False, "and" is going to be False.
所以为了使“and”为真,这两个对象都必须为真。
So in order for "and" to be True, both of the objects need to be True.
最后,我们有“not”操作,它简单地否定对象的值。
Finally, we have the "not" operation, which simply negates the value of the object.
所以,如果我们说不正确,Python会给我们错误。
So if we say not True, Python gives us False.
如果我们说notfalse,Python就会返回True。
And if we say not False, Python returns to us True.
我们经常需要比较程序中的对象。
We often need to compare objects in our programs.
Python中总共有八种不同的比较操作。
There are a total of eight different comparison operations in Python.
虽然这些常用于数字类型,但实际上我们也可以将它们应用于其他类型。
Although these are commonly used for numeric types,we can actually apply them to other types as well.
例如,如果要比较两个序列,比较将按元素进行。
For example, if you’re comparing two sequences,the comparison is carried out element-wise.
因此,您将第一个序列中的第一个元素与第二个序列中的第一个元素进行比较,依此类推。
So you’re comparing the first element of your first sequence to your first element in your second sequence, and so on.
这样的比较结果总是一个布尔类型,无论是真是假。
The result of a comparison like this is always a boolean type, either True or False.
通过一个涉及数字的简单例子,也许最容易理解这些比较。
It’s perhaps easiest to understand these comparisons through a simple example that involves numbers.
那么,让我们试试其中的两个。
So let’s try out a couple of them.
假设您正在比较两个数字。
Let’s say you are comparing two numbers.
我们可能会问Python,2比4小吗?
We might ask Python, is 2 less than 4?
Python对我们来说是真实的。
Python returns True to us.
我们也可以问,2是否小于或等于,比如说,2?
We can also ask, is 2 less than or equal to, say, 2?
在这种情况下,答案也是正确的。
And in this case, the answer is again True.
我们可以用两个等号来检验等式。
We can test for equality by using two equal signs.
2等于2,因此Python向我们返回True。
2 is equal to 2, so Python returns True to us.
最后我们可以用感叹号或感叹号来问,两个物体是否不相等。
And finally we can ask, are two objects not equal to one another,by using the exclamation mark or exclamation point.
在这种情况下,答案是错误的,因为2等于2。
In this case, the answer is False, because two is equal to 2.
这两个比较用于测试两个对象是否相同。
These two comparisons are used to test whether two objects are the one and the same.
请注意,这与询问两个对象的内容是否相同不同。
Notice that this is different than asking if the contents of two objects are the same.
让我们看看这意味着使用一点代码。
So let’s see what this implies using a little bit of code.
我们可以询问Python,包含数字2和3的列表是否与包含数字3和3的列表相同。
We could ask Python if the list that contains numbers 2 and 3 is the same as the list containing numbers 3 and 3.
当然,在这种情况下,答案是错误的。
The answer is, of course, False in this case.
如果我们修改第二个列表,现在两个列表中都有数字2和3。
If we modify the second list, now both lists have the numbers 2 and 3 in them.
答案将是正确的。
The answer is going to be True.
这些清单的内容相同。
The lists are identical in content.
但是,如果我们想询问第一个列表是否与第二个列表是同一个对象,我们将使用“is”比较。
However, if we wanted to ask if the first list is the same object as the second list, we would use the "is" comparison.
Python告诉我们这是错误的。
And Python tells us that this is False.
如果我们想知道第一个列表是否与第二个列表不是同一个对象,我们可以使用“is not”操作。
If we’d like to know if the first list is not the same object as the second list, we can use the "is not" operation.
在本例中,Python返回True。
And in this case, Python returns True.
我们这里有两个列表。
So we actually have two lists here.
它们碰巧有相同的内容,但我们有两个对象。
They happen to have the same contents, but we do have two objects.
这就是为什么这个比较返回False。
That’s why this comparison returns False.
我们如何测试浮点数和整数这两个数的相等性?
How would we test equality of two numbers that are a floating point number and an integer?
因此,我们可以看到测试2.0是否等于2.0时如何返回True。
So we can see how testing if 2.0 is equal to 2.0 returns True.
但是如果我们问Python,2.0是否等于2?
But what happens if we ask Python, is 2.0 equal to 2?
在本例中,2.0是一个浮点数,而2是一个整数。
In this case 2.0 is a floating point number, whereas 2 is an integer.
在这种情况下会发生以下情况:
What happens in this situation is the following:
Python接受第二个数字,即数字2,一个整数——它将其转换为浮点数。
Python takes the second number, which is number 2, an integer– it turns that into a floating point number.
整数2的浮点表示形式为2.0。
The floating point representation of the integer 2 is 2.0.
因此,现在我们将隐式地比较2.0和2.0。
So now we are comparing implicitly 2.0 to 2.0.
因此,答案将是正确的。
Therefore the answer is going to be True.

Python 数据分析
本站所提供的部分资源来自于网络,版权争议与本站无关,版权归原创者所有!仅限用于学习和研究目的,不得将上述内容资源用于商业或者非法用途,否则,一切后果请用户自负。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容资源。如果上述内容资对您的版权或者利益造成损害,请提供相应的资质证明,我们将于3个工作日内予以删除。本站不保证所提供下载的资源的准确性、安全性和完整性,源码仅供下载学习之用!如用于商业或者非法用途,与本站无关,一切后果请用户自负!本站也不承担用户因使用这些下载资源对自己和他人造成任何形式的损失或伤害。如有侵权、不妥之处,请联系站长以便删除!
金点网络-全网资源,一网打尽 » Python数据分析(中英对照)·Expressions and Booleans 表达式和布尔值

常见问题FAQ

免费下载或者VIP会员专享资源能否直接商用?
本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。
是否提供免费更新服务?
持续更新,永久免费
是否经过安全检测?
安全无毒,放心食用
jamin

jamin 大神

下一篇
网络协议-组播介绍

相关推荐

Python数据分析(中英对照)·Examples Involving Randomness 涉及随机性的例子

Python数据分析(中英对照)·Examples Involving Randomness 涉及随机性的例子

Python数据分析(中英对照)·Modules and Methods 模块和方法

Python数据分析(中英对照)·Modules and Methods 模块和方法

Python数据分析(中英对照)·Strings 字符串

Python数据分析(中英对照)·Strings 字符串

Python数据分析(中英对照)·Lists 列表

Python数据分析(中英对照)·Lists 列表

Python数据分析(中英对照)·Introduction to NumPy Arrays NumPy 数组简介

Python数据分析(中英对照)·Introduction to NumPy Arrays NumPy 数组简介

标签云
Android Atom ExecutorService ForkJoin GM GM后台 GM授权后台 H5 Java Javascript Linux手工服务端 pipbestcom Python ReentrantLock synchronized ThreadLocal volatile Win一键即玩服务端 一键端 传奇 写作 创业 单机 后台 商业端 外网 安卓 安卓苹果双端 工具 手工端 手游 搭建教程 教程 数据分析 文案 游戏源码 端游 经典 网单 职场 自媒体 视频教程 详细搭建教程 运营后台 页游

近期文章

  • 回合手游【逍遥西游之繁华西游】最新整理单机一键既玩镜像服务端_Linux手工端_GM后台_教程
  • 最新整理精品回合制手游【天书奇谈3D混沌完整版】VM一键单机版_linux手工外网端_隐盟视频教程_授权GM后台_双端
  • 典藏修真页游【诸仙列传OL】最新整理Win系服务端_GM工具_详细外网搭建教程
  • MT3换皮MH【浮生若梦尊享挂机修复版】最新整理单机一键即玩镜像端_Linux手工服务端_安卓苹果双端_GM后台_详细搭建教程
  • 大话回合手游【最新引擎之缥缈西游渡劫版】最新整理Linux手工服务端_安卓苹果双端_管理后台_CDK后台_详细搭建教程_视频教程

分类

  • | wordpress插件 |
  • | wordpress模板 |
  • | 其它模板 |
  • | 帝国模板 |
  • | 织梦插件 |
  • | 织梦模板 |
  • A5源码
  • Android软件
  • APP引流
  • E语言
  • H5
  • LUA
  • QQ营销
  • SEO推广
  • Windows软件
  • 体育运动
  • 信息数据
  • 创业专题
  • 办公教程
  • 口才演讲
  • 名师讲座
  • 商城/淘客/交易
  • 小吃技术
  • 小说/漫画/阅读
  • 建站教程
  • 引流脚本
  • 影视/音乐/视频
  • 影视资源
  • 微信/微商/微擎
  • 微信小程序
  • 微信营销
  • 微擎模块
  • 手游源码
  • 技能学习
  • 抖音课程
  • 摄影教程
  • 棋牌教程
  • 模板/主题/插件
  • 游戏源码
  • 爆粉引流
  • 理财/金融/货币
  • 生活老师
  • 电商客
  • 电子文档
  • 电脑教程
  • 社群营销
  • 站长工具
  • 精品网单
  • 系统工具
  • 素材资料
  • 综合资料
  • 编程经验
  • 网站源码
  • 网络安全
  • 网赚教程
  • 网赚源码
  • 考研资料
  • 脚本/AI/智能
  • 自媒体
  • 英语学习
  • 营销软件
  • 设计素材
  • 说书小说
  • 贴吧引流
  • 软件工具
  • 软文营销
  • 逆向软件
  • 音频讲座
  • 页游源码

提供最优质的资源集合

立即加入 友好社区
金点网络-全网资源,一网打尽

新一代全网资源综合门户网(www.pipbest.com-金点网络)专注服务于互联网,提供各类最新最全的免费源码下载(PHP、ASP、JSP、.NET),更提供免费工具,免费源码下载,软件下载,素材下载,赚钱教程下载,交流论坛等网站运营相关的一切内容,为网友搜罗最有价值的网站源码下载与技术教程等服务!

服务目录
  • 金点OpenAPI
  • 金点云
  • 金点支付
友情链接
  • 数媒派
  • 国家电网
快速搜索

本站由Nice强力驱动

声明: 本站部分内容属于原创转载请注明出处 如有侵权行为请严格参照本站【版权声明】与我们联系,我们将在48小时内容进行处理!

本站部分内容属于原创转载请注明出处 如有侵权行为请严格参照本站【版权声明】与我们联系,我们将在48小时内容进行处理!
© 2016-2023 PipBest.Com - 金点网络 & 金点部落. All rights reserved 京ICP备2022005359号-1
  • 关注有礼
  • 签到
  • 客服
    官方QQ群 常见问题 FAQ

    在线客服

    点我联系

    直接说出您的需求!
    切记!带上资源连接与问题!

    工作时间: 9:30-21:30

  • 暗黑
    模式
  • 全屏
  • 投稿
    赚钱
  • 首页

  • 签到

  • 切换

  • 客服

金点网络-全网资源,一网打尽
  • 登录
  • 注册
or
or
忘记密码?
金点网络-全网资源,一网打尽
  • 网站首页 ►
    • 金点部落
    • 小游戏
    • OpenAPI
    • 设计资产导航
    • 升级会员
  • 技能学习 ►
    • 体育运动
    • 办公教程
    • 口才演讲
    • 小吃技术
    • 建站教程
    • 摄影教程
    • 棋牌教程
    • 网赚教程 ►
      • 爆粉引流
      • 自媒体
      • 贴吧引流
  • 网站源码 ►
    • 商城/淘客/交易
    • 小说/漫画/阅读
    • 影视/音乐/视频
    • 微信/微商/微擎
    • 理财/金融/货币
    • 模板/主题/插件
  • 游戏源码 ►
    • 精品网单
    • 端游源码
    • 手游源码
    • 页游源码
  • 素材资料 ►
    • 电子文档
    • 综合资料
    • 考研资料
    • 设计素材
    • 音频讲座 ►
      • 人文艺术
      • 名师讲座
      • 说书小说
  • 软件工具 ►
    • Windows软件
    • MacOS软件
    • Android软件
  • 寄售资源
    ►
    • 游戏源码
    • 网站源码
    • 软件源码
  • 公益服
×
u3** 刚刚下载了 爆款吸金文案训练

    全网资源·一网打尽

  • 金点出品,必属精品!
  • 发布原创内容,获取高额提成!
  • 我们与你共创美好数字生态!
  • 无特殊说明密码默认:pipbest.com