语法“exp1<<variable<<exp2”在Python中是如何工作的?[closed]
发布时间:2022-04-26 15:55:45 158
相关标签: # node.js
当我在看书的时候,我发现了这个例子。
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
工作
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报