Categories: Tutorials

Python Slicing: A Tutorial In 6 Easy Points


Python is an advanced, general-purpose language of programming that is generally used to create web applications and graphical user interfaces. Its dynamic typing and binding options make it extremely prominent in rapid growth in the application. We’ll learn about Python slicing in this post, which is an important subject in programming in Python.

In Python, a string data form is a set of one or more individual characters: letters, whitespace characters, numbers, or symbols. Since the Python slice string is a list, it can be accessed using indexing and slicing in the same way that other sequence-based data types can.

Let’s see what the topics required to understand how to slice a list in Python are.

  1. What is an Index?
  2. What is Python slicing?
  3. Python slice with negative indices
  4. The step-by-step slicing process
  5. Understanding the Slice() Operation/Function in Python
  6. Delete and Insert Multiple Items with the help of Slicing

1. What is an Index?

Referring to an iterable element by its place within the iterable is referred to as indexing – a character in a string is assigned an index number, and its index number can access each character.

In a Python list slice, string, or tuple, an index is the location of a single character or element. The value of the index is always one number less than the number of products and starts at zero. We move a Positive index (which we want to access) in square brackets while using positive indexing. The index numbers begin at 0 and go up from there (which denotes the first character of a string). 

We move the Negative index (which we want to access) in square brackets in this indexing method. The index number begins at -1 in this case (which denotes the last character of a string).

You may also use negative indexing in Python from the end of the list, where [-1] returns the last element. This is extremely useful because it eliminates the need to programmatically determine the duration of the iterable to deal with elements at the end. 

Let’s know the aspect of indexing and slicing in Python.

2. What is Python slicing?

The slice function is the most important part of Python slicing. It enables programmers to extract data from a string of characters. In this post, we will be able to see a variety of methods for doing so. The Python slicing isn’t limited to strings; it can also be extended to tuples and lists.

In Python, slicing is the process of extracting a substring from the main string.

The Syntax would be: Object [start:stop:step]

“Start” is used to specify the starting index of a slice 

“Stop” is used to specify the ending element of a slice

If you want to miss or skip a few steps, use one of these. This encapsulates the slicing operation in Python.

3. Python slice with negative indices

The process of negative slicing starts at the bottom of the object/list.

Another method of slicing is using the negative index. This is also a good method for reversing substrings. The string slicing function now has three parameters. The first is the beginning index from the string’s end, the second is the finishing index, and the third is the interval.



name = “JIGSAW”



lst = [1,2,3,4,5,6,7,8]



tpl = (1,2,3,4,5,6,7,8)





4. The step-by-step slicing process

If you want to skip those objects, you may follow a specific move.



name = “JIGSAW”



lst = [1,2,3,4,5,6,7,8]



tpl = (1,2,3,4,5,6,7,8)





Basically, the string ‘JIGSAW’ is sliced from indexes one through seven in the illustration above. Since the step size was applied to two, you should get every second character in the output, beginning with the first index.

5. Understanding the Slice() Operation/Function in Python

The slice() method removes a portion of data and reverts it to new data. This means that users can choose a set of items/elements without modifying them.

The Syntax would be: slice(start,stop,step)

For Example:

In [24]:


name = ‘JIGSAW’

a = slice(1,4) 



1st [1,2,3,4,5,6,7,8]

b = slice(1,4)



tpl = (1,2,3,4,5,6,7,8) 

c- slice(1,4)



1st = [1,2,3,4,5,6,7,8]

d = slice(1,6,2)

print (1st [d])


[2, 3, 4]

[2, 3, 4]

[2, 4, 6)

6. Delete and Insert Multiple Items with the help of Slicing

1) Inserting Slice in Python

Objects may be added to a list besides having to replace other components. 

In [27]:

# Insert at the start

X = [‘a’, ‘b’, ‘c’,’d’] 

X[0] = [1, 2, 3] 


# Insert at the end

X= [‘a’, ‘b’, ‘c’,’d’] 

X[len(X):] = [1, 2, 3] 


[1, 2, 3, ‘a’, ‘b’, ‘c’,’d’] 

[‘a’, ‘b’, ‘d’, 1, 2, 3]

2) Deleting slice in Python

Using the del statement, users can exclude several items from the structure of the data. Following is an exemplification of the Python array slice.


In [17]: 

from array import *

array1 array(‘i’, [1,2,3,4,5])



array(‘1’, [2, 3, 4, 5])


We covered two main concepts: Indexing and Python slicing. We learned about how slicing, negative slicing, and step-indexing work. Understanding Python slicing necessitates a grasp of both definitions. We will learn more about data frame slicing in Python, reverse slicing in Python, and Python advanced slicing in future articles.

If you are interested in making a career in the Data Science domain, our 11-month in-person Postgraduate Certificate Diploma in Data Science course can help you immensely in becoming a successful Data Science professional. 


Sauvik Acharjee

Published by
Sauvik Acharjee

Recent Posts

Books on Analytics

Analytics is a vast field. At the one end, it overlaps with statistics and higher…

Career in analytics in a KPO

Do you love to explore and investigate information? Do you find spreadsheets to be a…

Indian companies using analytics

India has developed into the global hub for analytics. A large number of MNCs have…

IBM: Betting big on analytics

International Business Machines Corp. Or IBM as it is popularly known recently announced its restructuring…

How to build a successful career in analytics

So you have got a job as an analyst in your dream company? Here are…

What’s the sentiment on “sentiment analysis”?

What's the sentiment on "sentiment analysis"? Is the field ready to take off?