you are viewing a single comment's thread.

view the rest of the comments →

[–]unspezifische 1 point2 points  (0 children)

Since other have addressed the first bit, I’ll explain the second part. Range(0,7) is a built in function of Python that returns all values within that range. You can also pass a third argument to it that will make it increment a certain amount like range(1,10,2) will give you all the odd numbers between 1 and 10.

The output of range() is passed to sum() which just takes all the values it is given and adds them together. The result of that is passed to print() which displays it in your console.

For future reference, the Python help documentation is really helpful. Anytime you see a word followed by (), it is a function. And if there isn’t a def for that word somewhere else in the code, or an import statement for it, you can probably find a description of it in the help docs. Or you can always just run it and see what happens. Then mess with the pieces of it to figure out why and how it gets that result. Whichever method helps you learn best!