Why keep using len() function in the slice notation?


#1

Sure, the new_word[1:len(new_word)] is technically correct, however it takes up more space and is more prone to bugs than new_word[1:]. Why not add an extra step to teach that a skipped index is assumed to be the first/last one?


#2

this way is actually more stable ,

than,

because the first method will always run only up to new_word's length.


#3

Are you implying that the second method won't?


#4

Not at all what I'm saying is that the fist method is definite.


#5

The second method is definite too. Also it would save you from a nasty bug if you were to rename your variables, e.g.:
new_word becomes temp_word, and you might end up with
temp_word[1:len(new_word)]


#6

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