why? the len function calculates the length of the argument passed, which is the latest version of the string
As I was trying to explain, new_word gets all its elements when the three items are added together. In the process of adding [1:len(new_word)] + first +pyn, how will len(new_word) get the final size in advance?
Sorry to come again on this. When the argument is being evaluated (i.e. new_word), its latest number of elements are not included yet.
but its two steps:
new_word = word + first + pyg
new_word = new_word[1:len(new_word)]
If you want to do this in one step, you have to use word
:
new_word = word[1:len(word)] + first + pyg
which i think yields the same outcome.
Thank you very much. This was also what I was thinking.
This is like answering a simple question in a complicated way. Oh, us beginners!
Thank you for keeping it straight forward.
to do it in one step and yield the same outcome it would be:
new_word = word[1:len(word)] + first + pyg
This worked for me: I used a variable that indicates the length of the string [using len()] and used it as the last character or end of string: str[x:{variable}]. If you noticed, this is almost the same as your exampleāonly that you used len(str). Wow! Iām a first-time Python learner and I realized how versatile Python is. But I think I havenāt seen anything yet.
Maybe Iām slow but I still donāt understand⦠Especially because in the solution portion new_word and itās string containing it is nowhere to be found. Not even the previous string the project had you do.
tldr;