is it more efficient to use "if x in range(y, z):" or "if x >= y and x < z"?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By AfterCadaver

Just a simple question for one concerned with memory. Does it matter in either case which I choose to check if a value is between two numbers?

:bust_in_silhouette: Reply From: rustyStriker

Assuming if x in range(y,z) works the way i expect it to work I believe the latter will be more efficient, as for you to possibly check if an item is in an array you have to loop through it(assuming the program doesn’t recognize that the array is defined easily with a mathematical function), so checking for bounds is better as if x >= y and x < z rather than if x in range(y,z)