<Below this line, add a link to the EXACT exercise that you are stuck at.>

<What do you expect to happen instead?>

I saw a similar post to mine explaining that both ways work, but I want to understand why code academy put the additional verbiage in if it does not need it.

<new_word = new_word[1:len(new_word)]>

but as discussed in another post, the below way of doing it also works. Why would you do it the long way if the way below works? I just want to understand the reasoning.

<new_word = new_word[1:]>


because it fits the python philosophy:

Explicit is better than implicit

codecademy follows this principal by explicitly including the length at which the slice should stop

to see the python philosophy run:

import this


Thank you for the explanation. That actually makes perfect sense.

Can you help me understand what new_word[1:len(new_word)]is actually saying?

I think I understand the first part new_word[1:to say remove the first letter of that new variable, but what is the len(new_word)]saying?

I understand it is meant to count length, but it does not seem to have a major function if it can be done without. What should I be gathering in my head from reading that additional statement?


you understand that we use string slicing here? We want to have part of a string, we achieve this using string slicing.

the general syntax is:

"your string"[start:stop]

so len(new_word) is the stop value of our slice.

true, but by using explicit (stating stop value), looking at the code more quickly tells us what the code is doing. Making the code easier to understand and more maintainable (for other developers going through your code)

in a program of 10 lines, this is not super important, but its better to pick up this habits (following python philosophy, and using explicit ) in the beginning, then having to add them later into your skillset


Thank you for the detailed explanation. It definitely makes a lot more sense.

So it is meant to tell other coders that the slice is being stopped specifically at that variable/value correct?

Could another variable actually even go in that spot aside from telling it to grab additional letters like [1:3]?

Why not just put [1:(new_word)] why add the len?

Sorry for all the questions I just really want to get good at this and I want to fully understand what I am looking at and the purpose.


or for yourself, if you come back to a project after a longer time. Using explicit will make it easier to understand what the code does

that is possible, yes

because the stop value of string slicing needs to be an integer, new_word is a string


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.