实现说明
真正干活的是函数 in_band,其余都是接线。
使用要点
in_band是公开入口,文件里其余部分都是为它服务的内部实现。
常见问题
包管理器会看到什么?
一份空的依赖清单。示例没有需要抓取的导入。 文件在加载时定义 in_band。
主要签名是 def in_band(x)
核心语句
def in_band(x):
return 0 < x < 10
代码示例
# 0 < x < 10 is one expression: each link compares the middle value once
def in_band(x):
return 0 < x < 10
print(in_band(5), in_band(-1), in_band(10))
# Equivalent to: (0 < x) and (x < 10) — x is evaluated only once
x = 5
print((0 < x) and (x < 10))
# Chaining mixes operators and equality links
a, b, c = 1, 1, 2
print(a == b < c)
print(a < b < c)
# Strings order lexicographically in the same chained style
print("apple" < "banana" < "cherry")