有一个整数值x,需要检查它是否在start和end值,因此我编写以下语句:
x
start
end
if x >= start and x <= end: # do stuff
发布于 2018-03-27 04:34:17
在Python中,情况是这样的:
if start <= x <= end:
参考资料:
https://docs.python.org/2/reference/expressions.html#not-in
发布于 2018-03-27 05:40:43
可以改写为:
start <= x <= end:
或:
r = range(start, end + 1) # (!) if integers if x in r: ....
相似问题
领取专属 10元无门槛券
AI混元助手 在线答疑
洞察 腾讯核心技术
剖析业界实践案例