0

I have a list alphabets = ["A","B",'C','D','E','F','G','H','I','J']

I can print the whole thing print(alphabets)

but I want to print it to the end, without starting from index 0 print(alphabets[1:9])

This only works when I know the end index.

So, considering that the list may change, how do I print the from any point other than index 0 and print to the end without changing the code as well?

1 Answers1

0

You can leave the end index empty and it will be interpreted as "until the end of the sequence":

alphabets = ["A","B",'C','D','E','F','G','H','I','J']

print(alphabets[1:])

#output
['B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']