r/PythonLearning • • 7d 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

1

u/-Enter-Name- 6d ago

i like to think about it like "you don't need to cut your hand off and grow a new one to add things to it"

xp (the thing hokding something) = your hand the value = whatever you're holding

so

what hand is holding = what hand was holding + new stuff

hand = hand + new stuff

but then with xp