Python-简单的按位或

标签 python simpy

现在我学习了python的simpy库。 你能解释一下为什么在这个example中使用bitwise-or吗? 。为什么我们不能使用简单的 or 语句。

results = yield req | env.timeout(patience)

最佳答案

来自 SimPy 的文档 Core Event Types

This class also implements and() (&) and or() (|). If you concatenate two events using one of these operators, a Condition event is generated that lets you wait for both or one of them.

这意味着 reqenv.timeout(patience) 都是事件,我们将生成第一个发生的事件。即

results = yield (req | env.timeout(patience))

要回答您最初的问题,您似乎可以使用 or 来代替,但这可能不会使实际情况变得更清晰,并且如果人们认为它是常规的旧 or ,则可能会导致编辑错误.

关于Python-简单的按位或,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36066542/

相关文章:

python - 从结构化数组中删除 `dtype` 字段

python - 并发支付控制

Python:有效计算字典列表中键的唯一值的数量

python - 我在 (y) 函数中遇到 for(x) 问题

python - 如何识别 SimPy 模拟中的耗时任务?

python - 类型错误 - Python Simpy

python - 如何删除字符串的日期时间部分?

simulation - 我怎样才能让一个进程等待多个资源?

python - 蒙特卡罗模拟 : Underlying distribution parameter changes during simulation run based on conditions

python - 今天使用哪些书籍来学习离散事件仿真?