How are [-1:] and [-1] different?

Why is the solution different when I use lst1[ -1: ] vs lst1 [ -1 ] ? The output prints [ 5 ] vs 5 which is what the program is looking for.

Slicing and indexing are not the same thing.

A slice returns a list; a list element accessed via indexing returns the element.

1 Like

Oh, ok. Thank you for the explanation.

1 Like