Foreword
I've been playing python for a long time, but I can't learn anything systematically and I need to check the information.Recently, when I was reading the program, I encountered a knowledge blind spot. This content is not the same as what I have mastered before.Therefore, it is recorded here for later reference.
Content
Slicing is a commonly used method in data processing, whether it is list, numpy or pandas, but the specific slicing method has not been systematically summarized. Taking this opportunity to summarize, the main slicing methods are as follows:
[-1] [:-1] [::-1] [n::-1] are all methods of using slices in python
[-1]: Get the last element;
[:-1]: Get all the other elements except the last element (I didn’t expect this usage, I thought it was from the beginning to the end);
[::-1]: Reverse the first to the last element and take it out;
[n::-1]: Reverse the first to the nth element and take it out.
References
[-1] [:-1] [::-1] [n::-1] usage of slice in python