In this tutorial, you’ll learn about slicing in Python, list slicing, flip lists using slicing, string slicing, slicing NumPy arrays, and more

Programming in Python involves frequently working with sequential or ‘indexed’ data. Indexed data are the ones stored in such structures that allow their access using indices.

Such data can be of varying lengths, from a few elements to hundreds of thousands of elements.

However, most of the time, we are interested in working only on a small subset of the data. While the data may be of length 1000, we may be interested in processing only the first 10 elements. So we should extract only the relevant portion of the data.

Such extraction of a subset of data is called slicing. In this tutorial, we will look at the different ways of slicing various types of data in Python. We will see how slicing is used to access and modify different portions of sequential data.

Table of Contents

  • Slicing Lists in Python
    * List Indexing
    * List Slicing
  • Modifying Lists using Slicing
  • Flip a List in Python with Slicing
  • String Slicing in Python
    * Finding a substring using slicing
    * Deleting a character from string using slicing
    * Replacing a word in a Python string using slicing
    * Reversing a Python string using slicing
  • Slicing using slice() method
  • Slicing NumPy arrays
  • Slicing Pandas Dataframes
  • Conclusion

#python #programming #developer

The Complete Guide to Slicing in Python
3.65 GEEK