复制成功
请遵守本站许可
REPORT
Chapter_Post // Field_Report

Post_Ref: RL-PYTHON逻辑

2026.04.08

逻辑运算(与,或)

Echo HaoRan
Echo HaoRan
#StudyProject
ANALYSIS

# 逻辑运算符#

我们还应该学习的一件事是逻辑运算符。

逻辑运算符, 也称为布尔运算符,结合并评估两个条件。他们是 andor, 和 not 运营商:

  • and 返回 True 如果两个条件都是 True, 并返回 False 否则。
  • or 返回 True 如果至少一个条件是 True, 和 False 否则。
  • not 返回 True 如果条件是 False, 反之亦然。

以下是一些示例:

PRTCL // PY
if hunger > 4 and anger > 1:
print('Hangry')

如果 hunger 变量大于 4  的 anger 变量大于 1,则程序打印“Hangry”。

PRTCL // PY
if coffee > 0 or bubble_tea > 0:
print('😊')

如果 coffee 变量大于 0 或者 的 bubble_tea 变量大于 0,则程序会打印笑脸。

PRTCL // PY
if not tired:
print('Time to code!')

如果 tired 变量是 不是 True, 然后程序打印“是时候编码了!”

所以你可能想知道: and 和 or 非常相似,我怎么记得两者之间的区别?让我们以表格形式将其分解:

一个A 和 BA 或 B
FalseFalseFalseFalse
FalseTrueFalseTrue
TrueFalseFalseTrue
TrueTrueTrueTrue
R P
Rhine Lab Pioneer Division
Auth_Verified: 2026.04.08
// END OF POST

订阅

通过 RSS 订阅本站,新文章发布时第一时间收到通知。

Follow
Classified
Chapter_06
Protocol_Ref: CC-BY-NC-SA-4.0

逻辑运算(与,或)

Author: CHONGXIReleased: 2026.04.08

Licensed under CC BY-NC-SA 4.0

评论

© 2025-2026 EchoSpace
Powered by Astro & echohaoran Non-Collaborative_Entity // Protocol_V.4.21