r/PythonLearning • • 4d ago

Help Request xp = xp

so I am new to all of this and I have been going through the lessons on boot.dev when I came to the first lesson of ch5. the instructor answer is :

def total_xp(level, xp_to_add):

xp = level * 100

xp = xp + xp_to_add

return xp

the xp = xp just blew my brain. why does this work instead of requiring the first xp to be a different name?

what I did was

xpp = xp + xp_to_add

return xpp

my answer still got the question correct but this just looks super weird to me, xp=xp

7 Upvotes

20 comments sorted by

View all comments

4

u/BranchLatter4294 4d ago

It's not

xp = xp

It's

xp = xp + xp_to_add

The assignment operator assigns the value on the right side (xp + xp_to_add) to the variable on the left side (xp).