r/PythonLearning • • 5d ago

i am stuck with the range function

sorry but i am gonna crash out because of the range function i cant understand it well to use it this is driving me crazy any one could give me a video explaining everything i dont mind it being an hour long

9 Upvotes

33 comments sorted by

View all comments

1

u/Due-Mortgage-6854 5d ago edited 4d ago

It's easy don't worry range(start, stop, step)

Now as example, let's say

  • You book time off work starting the 10th and tell your boss, "I'll be back at my desk on the 15th." You are off on the 10th, 11th, 12th, 13th, and 14th. Because you return on the 15th, that day isn't part of your vacation. That is why Python stops right before the second number So your start here is 10 and stop is 15!

  • You decide to hit the gym every other day for the month of June (which has 30 days), starting on June 1st. You start on the 1st, skip a day (step = 2), go on the 3rd, 5th, 7th, all the way up to the 29th. You set the stop number to 31 so that the 30th isn't accidentally cut off before the month ends. Here start is 1, stop 31 and step 2!

  • If you want some more help : https://discord.com/invite/QWGWKFVYyh