当我在看书的时候,我发现了这个例子.
def apply_discount(product, discount):
price = int(product['price'] * (1.0 - discount))
assert 0 <= price <= product['price']
return price
我以前从未见过语法0 <= price <= product['price']
,很明显,它在测试价格,应该是>= 0
和<= product['price']
.我测试了这个功能,它按预期工作.我想做更多关于语法0 <= price <= product['price']
的测试.
a = 7
if 0 << a << 10:
print('a is greater than or equal to 0 and less than or equal to 10')
else:
print('a is not greater than or equal to 0 and less than or equal to 10')
它总是打印a is not greater than or equal to 0 and less than or equal to 10
张.为什么会这样?0 << a << 10
到底起什么作用?