Why does new_word know how long it is



Hello. I'm not necessarily stuck, just confused.


Why does this work? How does new_word know how long it is before it has actually been told exactly which characters from the string variable "word" are being allocated to it? Should it be like this?:


Thanks for any help. I really want to understand this before moving forward.


It doesn't. That line will throw an error.

new_word = word + first + pyg

Now we've defined the string, and can write,

new_word = new_word[1:len(new_word)]


But you assign new_word on this line, how does it know the length of new_word then? That is the question


It knows from this,

new_word = word + first + pyg


ofc, silly me. Thank you mtf


This screenshot shows it working.


Working in the sense that it passes you.

It doesn't do what it should. Refresh page and run it again.


All right, now it throws an error. But why didn't it do that the first time? As you can see from the output in the screenshot I provided it ran fine :confused:


Refreshing the page has the effect of giving you a new instance of a Python interpreter which means that everything you had defined earlier is now gone.

Your code was relying on such a value, using something it did not define.


aaaaand my brain isn't scrambled egg any more. Thanks, bro!


Further, the way you would express "all but the first" is:


Left out parameters are given default values. [:] for example, creates a copy.


Which is true, but not what the instructions ask for. The above longer expression is what is in the instructions.