python关键字和保留字_或带有Python示例的关键字
python关键字和保留字
Python或关键字 (Python or keyword)
or is a keyword (case-sensitive) in python, it is a logical operator actually, it is used to validate more than one conditions. It is similar to Logical OR (||) operator in C, C++ programming. It requires a minimum of two conditions and returns True – if one or more condition(s) is/are True.
还是 python中的一个关键字(区分大小写),实际上它是一个逻辑运算符,用于验证多个条件。 它类似于C , C ++编程中的逻辑OR(||)运算符。 它至少需要两个条件并返回True –如果一个或多个条件为True 。
Truth table for "or" keyword/operator
“或”关键字/运算符的真值表
Condition1 Condition2 (Condition1 or Condition2)
True True True
True False True
False True True
False False False
Syntax of or keyword/operator:
或关键字/运算符的语法:
condition1 or condition2
Example:
例:
Input:
a = 10
b = 20
# conditions
print(a>=10 or b>=20)
print(a>10 or b>20)
Output:
True
False
或运算子的Python范例 (Python examples of or operator)
Example1: Take two numbers and test the conditions using or operator
例1:取两个数字并使用或运算符测试条件
# python code to demonstrate example of
# or keyword/operator
a = 10
b = 20
# printing return values
print(a>=10 or b>=20)
print(a>10 or b>20)
print(a==10 or b==20)
print(a==10 or b!=20)
Output
输出量
True
False
True
True
Example 2: Input a number and check whether it is divisible by 2 or 3
示例2:输入一个数字并检查它是否可以被2或3整除
# Input a number and check whether
# it is divisible by 2 or 3
# input
num = int(input("Enter a number: "))
# checking num is divisible by 2 or 3
if num%2==0 or num%3==0:
print("Yes, ", num, " is divisble by 2 or 3")
else:
print("No, ", num, " is not divisble by 2 or 3")
Output
输出量
First run:
Enter a number: 66
Yes, 66 is divisble by 2 or 3
Second run:
Enter a number: 5
No, 5 is not divisble by 2 or 3
Example 3: Input a string and check whether it is "Hello" or "World"
示例3:输入一个字符串并检查它是“ Hello”还是“ World”
# Input a string and check
# whether it is "Hello" or "World"
# input
string = input("Enter a string: ")
# checking the conditions
if string=="Hello" or string=="World":
print("Yes, \"", string, "\" is either \"Hello\" or \"World\"")
else:
print("No, \"", string, "\" is neither \"Hello\" nor \"World\"")
Output
输出量
First run:
Enter a string: Hello
Yes, " Hello " is either "Hello" or "World"
Second run:
Enter a string: World
Yes, " World " is either "Hello" or "World"
Third run:
Enter a string: IncludeHelp
No, " IncludeHelp " is neither "Hello" nor "World"
翻译自: https://www.includehelp.com/python/or-keyword-with-example.aspx
python关键字和保留字
python关键字和保留字_或带有Python示例的关键字相关推荐
- 以下可以采用python语言保留字的是-以下哪个选项不是Python语言的保留字?_学小易找答案...
[单选题]石灰的主要成分 [多选题]玻璃按照功能分类 [填空题]目前,使用最广泛的计算机所用的逻辑部件是 ____. [多选题]材料按照功能不同分为 [单选题]已知在计算机中存储了"大学计算 ...
- python使用del保留字定义一个函数-python中自定义函数的保留字是
基本使用(推荐学习:Python视频教程)def function_name(parameters): expressions Python使用def开始函数定义,紧接着是函数名,括号内部为函数的参数 ...
- python变量定义大全_详解python变量与数据类型
这篇文章我们学习 Python 变量与数据类型 变量 变量来源于数学,是计算机语言中能储存计算结果或能表示值抽象概念,变量可以通过变量名访问.在 Python 中 变量命名规定,必须是大小写英文,数字 ...
- python学什么东西_什么是Python?你应该学习和使用它的13个理由
如果您希望转向网站开发或软件开发,成为程序员中的一员,那么学习HTML,CSS和JavaScript的基础三重奏就不会出错.但要真正在拥挤的应用领域中脱颖而出,您还是需要学习其他编程语言. (上图为G ...
- python积木式编程_实例讲解python函数式编程
函数式编程是使用一系列函数去解决问题,按照一般编程思维,面对问题时我们的思考方式是"怎么干",而函数函数式编程的思考方式是我要"干什么". 至于函数式编程的特点 ...
- python展开函数方法_逐步展开Python详细教学—Python语法
Python语法–在Python世界迈出第一步 我们已经拥有了许多的编程语言,而且都有自己的特色,但是一种语言的独特之处在于它的特性.最终,是它的特点让它被选中或通过项目.因此,在开始更深入的Pyth ...
- python数据科学手册_小白入门Python数据科学
前言 本文讲解了从零开始学习Python数据科学的全过程,涵盖各种工具和方法 你将会学习到如何使用python做基本的数据分析 你还可以了解机器学习算法的原理和使用 说明 先说一段题外话.我是一名数据 ...
- python使用del保留字定义一个函数-Python使用什么保留字定义一个函数。
[单选题]Where was the First Continental Congress held? [单选题]对于集合S和T,下列不属于集合类型的操作是() [判断题]UPS系统的静态开关用于保护 ...
- 如何用python进行量化交易_从零开始学习Python和量化交易
Python的特点 1.易于学习:Python有相对较少的关键字,结构简单,和一个明确定义的语法,学习起来更加简单. 2.易于阅读:Python代码定义的更清晰. 3.易于维护:Python的成功在于 ...
最新文章
- 实习生笔试面试题总结
- XMLHttpRequest cannot load解决方案
- Maven依赖项的适用范围scope
- esri geometry-api-java的maven创建
- python导入pandas具体步骤方法_python导入pandas具体步骤方法
- phpst安装memcache扩展_在 Ubuntu/Debian 下安装 PHP7.3 教程
- [EOJ]2019 ECNU XCPC March Selection #1 F
- Kudu : kudu运行的时候-停止master RecoverableException: Failed to connect to peer master
- flutter text 自动换行_Flutter 即学即用——05 StatelessWidget vs StatefulWidget
- Pandas:DataFrame对象的基础操作
- DS1302+LCD1602=万年历
- python泰坦尼克号生存预测论文_python泰坦尼克号生存预测
- Flink实时数仓--ClickHouse数据可视化接口实现、Sugar 数据大屏
- ElasticSearch全文检索-从零到入门
- 硬件设备的软件测试,智能设备的软硬件测试都要测什么?
- 360视频质量评估标准:WS-PSNR,S-PSNR,CPP-PSNR
- 三菱模拟量fx3u4da_三菱模拟量输入模块FX3U-4AD与FX3U-4AD-ADP的区别
- swift Dictionary 字典
- 【论文阅读】Towards Graph Self-Supervised Learning with Contrastive Adjusted Zooming
- 用计算机的坏处300字作文,网络危害作文300字.docx
热门文章
- 8g可用 安装内存16g_同样是16g内存,为啥都选两条8G,不选16G单条,这难道有啥讲究?...
- JDBC【介绍JDBC、使用JDBC连接数据库、简单的工具类】
- angularjs中 $watch 和$on 2种监听的区别?
- 执行命令npm install XXX后仍然提示 Cannot find Module XXX
- 5.jQueryAjax
- 浅谈servlet与jsp的关系
- html中常见的小问题(1)
- 全方位分析web前端如何进行性能优化
- Nginx 使用try_files遇到的问题
- 深入理解softmax函数