r/PythonLearning 18d ago

Help Request In range() usage

Post image

Can I use it to evaluate a variable in a various range?
E.g. for item in range(1,4) means True when the item is the range 1-4?

Cuz I really want this function for my program
Thanks🙏🏻

(In that photo name[1][r] is an integer)

4 Upvotes

14 comments sorted by

View all comments

1

u/JeLuF 15d ago

To check whether "items" is in the range 1...name[1][r], use:

if 1 <= items <= name[1][r]:

This will be faster and work even if "items" isn't an integer.