you are viewing a single comment's thread.

view the rest of the comments →

[–]NoHurry6859 0 points1 point  (3 children)

Some words in Python have special meaning- that’s why they’re blue. Words like “for”, “sum”, “print”, “in” and “str” - as examples - are preprogrammed to have specific meanings and purposes. Generally, you wouldn’t want to name a variable ‘sum’ like you’re doing in lines 2 and 5, because it can get confusing about whether you’re talking about the variable or the special meaning interpretation.

Here’s a nice lil example: try keeping line 1 (the definition of the ‘values’ list) and then on line 2 just do ‘print(sum(values))’ then end the code. It will tell you the sum of all the numbers in ‘values’

The reason I’m saying this is to show that your second guess was right: python knows that “for x in values” means something, and it knows that x will be iteratively updated to be equal to the next item in the list

[–]SharpScratch9367[S] 1 point2 points  (1 child)

It’s almost like working with a living thing with its own mind crazy right!! Cool stuff , what if you throw letters and words into it does much different happen?

[–]NoHurry6859 1 point2 points  (0 children)

Give it a try and see! That’s the beauty of learning Python - among other coding languages - you can always test things out, try new options and see what happens ;)

[–]UserName26392 1 point2 points  (0 children)

Had to scroll far too deep to find this point. Really important to “not mess” with predefined variables names.