Python Code Challenges: Lists (Advanced) - 1. Every Three Numbers

https://www.codecademy.com/courses/learn-python-3/articles/advanced-python-code-challenges-lists

Hi there! Please can someone explain like I’m 5, the solution to the first question for the advanced lists challenges:

codecademy range Q

It’s stated that ‘The range function accepts the starting number, the ending number (exclusive), and the amount to increment by.’ But I can’t get my head around how the code knows what the ending and increment number is. Is this built in with the range/list function?

Many thanks

Hey arc,
I hope this explanation helps, I may be wrong and I often am. If I am someone else should please correct me or give me a better explanation myself.

A suitable way to understand this is with starting with you defining your function that takes in one argument, called ‘start’ which you defined. When you call this function you are going to return a list of numbers which start at your ‘start’ variable and goes up to, but not including 101.
The code knows what the ending number is because you defined it. A default way to look at creating lists in the future is by this list(range(start,end,increasing/decreasing by…)) OR more commonly known as range(start, stop, step )

Lastly yes this is built into the range function, not the list function. The list function simply tells python to display the output in a list, that’s all it does. Remember all these are built in functions, it is quite easy to understand how it was created. Simply by creating another function called(range) that takes in, inputs, sends it through a mathematical formula and outputs. To find the code to the range function is actually harder to find :sweat_smile:, but once you complete the advanced course of python you should be able to do it yourself and many other types of custom functions you will create.
Geoduck on your coding Journey! Tag me lets team up and assist each other once in a while.

2 Likes

Thank you so much for your reply!! This makes things much clearer.

When you say ‘range(start, end, increasing/decreasing)’ - is this how range can be used in general?

This massively helps my understanding, I’ll keep this in mind :slight_smile:

And thank you for allowing me to tag you etc. I’ll definitely be taking you up on the offer :slight_smile: !!

Yes that is correct, for now, that is how range is used in general. But as you advanced there multiple neat ways you can use the range function.

And thank you too for your kind response! :pray: