+ 6
variable i takes values from 0 to X-1 in for loop and that number in one iteration is added to res variable, res += 0, res += 1 ... res += 9. After every iteration variable i is bigger by one: 0,1...,9.
+ 2
variable i is declared on the third line
it goes through the range(10). that means it takes on values 0,1,2,3,4,5,6,7,8,9
in every iteration of the loop the value of i is added to th result
after 10 runs of the loop the variable res is returned by the function
+ 1
Code are normally reading/interpreting code line by line sequentially but for purposes of understanding a function sometimes people will just skip till the end and get the value of the function being called. In this case the sum(10) function was called in line 6. For testing purposes, you can always substitute the x with any number you prefer 100, 1000 or anything. I suggest you to use the code playground to test your code for better understanding.
As for the your deconstruction of line i will start with line 3 where the for loop resides.
line 3: for i in range(x):
variable i will be defined as the value from the range(x).
Just in case you might not know. range(x) creates a sequential list of numbers ranging from 0 to x, where x is whatever value you get after it is define. For example, if x is 10 then you will get a list from 0 to 10 not including 10 itself which is equivalent to [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
line 4: res + = i
Just as you say res + whatever i is. And thus, from your example code, the loop will iterate through the list created by range(x) and define i as each value in the list.
Assuming the x is 10 then
first iteration i = 0 and thus res += 0 # res is now 0
second iteration i = 1 and thus res += 1 # res is now 1
second iteration i = 2 and thus res += 2 # res is now 3
...
last iteration i = 9 and thus res += 9 # res is now 45
line 5: return res
return the value of res to the calling function.
In your case it is line 6.
line 6: print(sum(10))
print the value return by the function sum(10) which will be the value of res in your case.
In python, indention is used to distinguish between a loop, a condition or a function. I suggest you to check your indention to understand the code.
Based on the indention, line 1 until line 5 is the function. line 3 to 4 is the for loop. line 5 the return statement is actually part of the function only, not the loop. And lastly, line 6 is a standalone statement which is outside of the function.
Correct me if I am wrong.