

{"id":26604,"date":"2018-08-29T05:45:01","date_gmt":"2018-08-29T00:15:01","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=26604"},"modified":"2026-04-25T14:27:10","modified_gmt":"2026-04-25T08:57:10","slug":"python-slice","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-slice\/","title":{"rendered":"Python Slice Constructor &#8211; Python Slice String &amp; Slicing Tuple"},"content":{"rendered":"<p>Today, in this Python Tutorial, we will discuss Python Slice. First, we will see the meaning of Slicing in Python.<\/p>\n<p>Moreover, we will learn Python Slice() function with syntax and example. Also, we will see Python String and Tuples Slicing.<\/p>\n<p>At last we will discuss indexing to create Slice in Python.<\/p>\n<div id=\"attachment_26608\" style=\"width: 1210px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Slice-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-26608\" class=\"wp-image-26608 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Slice-01.jpg\" alt=\"Python Slice | Python Slice() Constructor\" width=\"1200\" height=\"628\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Slice-01.jpg 1200w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Slice-01-150x79.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Slice-01-300x157.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Slice-01-768x402.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Slice-01-1024x536.jpg 1024w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><p id=\"caption-attachment-26608\" class=\"wp-caption-text\">Python Slice | Python Slice() Constructor<\/p><\/div>\n<h3>What is Python Slice?<\/h3>\n<p><span style=\"font-weight: 400\">On our way up the learning curve for Python, we only need to deal with Python iterables not so huge. <\/span><span style=\"font-weight: 400\">But when building an application with it, we do not always need to retrieve the entire iterable. <\/span><\/p>\n<p><span style=\"font-weight: 400\">In such cases, slicing is useful as it lets us choose what to see and focus on. This aids readability and implements abstraction. <\/span><span style=\"font-weight: 400\">To slice an iterable, we use the slicing operator, that is [ ]. To separate the start, stop, and step values, we use the colon ( : ). <\/span><span style=\"font-weight: 400\">Say you want to declare a list with the values 1,2,3,4,5, and only want to see values 2,3, and 4. You can slice the list for that.<\/span><\/p>\n<p><strong>Why use slicing in Python?<\/strong><\/p>\n<ul>\n<li><strong>Clean code:<\/strong> To search a part of a list, you don&#8217;t need to write code in a loop. It makes the code short and easy to read.<\/li>\n<li><strong>Fast coding:<\/strong> Python is made to handle slicing quickly, which makes the data run faster.<\/li>\n<\/ul>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; list=[1,2,3,4,5]\r\n&gt;&gt;&gt; list[1:4]<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[2, 3, 4]<\/div>\n<h3>The Python Slice() Function<\/h3>\n<p><span style=\"font-weight: 400\">The slice() is a constructor that creates a Python Slice object to represent the set of indices that range(start, stop, step) specifies. <\/span><\/p>\n<p><span style=\"font-weight: 400\">With this, we can slice a sequence like a string, a tuple, a list, a range object, or a bytes object. <\/span><\/p>\n<p><span style=\"font-weight: 400\">These are all objects that support sequence protocols and implement __getitem__() and __len__(). <\/span><span style=\"font-weight: 400\">The slice() function returns a Python Slice Object.<\/span><\/p>\n<h3>The Syntax of Slice in Python<\/h3>\n<p><span style=\"font-weight: 400\">Let\u2019s talk about the syntax of Slicing in Python first:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">slice(stop)<\/pre>\n<pre class=\"EnlighterJSRAW\">slice(start, stop, step)<\/pre>\n<p><span style=\"font-weight: 400\">What are these parameters? Let\u2019s see:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>start-<\/strong> Where to begin slicing (Optional)<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>stop-<\/strong> Where to stop slicing+1<\/span><\/li>\n<li style=\"font-weight: 400\"><span style=\"font-weight: 400\"><strong>step-<\/strong> How much to increment between each index (Optional)<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">You\u2019ll see that we have two syntaxes. <\/span><\/p>\n<p><span style=\"font-weight: 400\">When we provide only one parameter value, it takes it to be the stop value. This means to start, and the steps are set to None.<\/span><\/p>\n<h3>Python Slice Example<\/h3>\n<p><span style=\"font-weight: 400\">Let\u2019s take a simple example of Python Slicing.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; slice(3)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">slice(None, 3, None)<\/div>\n<p><span style=\"font-weight: 400\">We can index this as:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; l=[1,2,3,4,5]\r\n&gt;&gt;&gt; l[slice(3)]<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[1, 2, 3]<\/div>\n<p><span style=\"font-weight: 400\">Note that it displays values at the indices 0, 1, and 2. It stops at index 3.<\/span><\/p>\n<h3>Python String Slice<\/h3>\n<p><span style=\"font-weight: 400\">We can slice a string in Python using the Python slice() method. We can also specify the interval. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Slicing a string may give us a substring when the step size is 1.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; s='helloworld'\r\n&gt;&gt;&gt; s[slice(1,6,2)]<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;elw&#8217;<\/div>\n<ul>\n<li style=\"font-weight: 400\"><strong>With positive indices-<\/strong><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400\">Like in the previous example, we use positive indices here.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; s='helloworld'\r\n&gt;&gt;&gt; s[slice(1,6)]<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;ellow&#8217;<\/div>\n<p><strong>With negative indices-<\/strong><\/p>\n<p><span style=\"font-weight: 400\">But like we\u2019ve seen with lists earlier, we can pass negative indices too. These are what it traverses from the right.<\/span><\/p>\n<p><span style=\"font-weight: 400\">To read the same value right to left, we do:<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; s='helloworld'\r\n&gt;&gt;&gt; s[slice(-5,-10,-1)]<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;wolle&#8217;<\/div>\n<p><span style=\"font-weight: 400\">Confused? Here\u2019s how we traverse right to left:<\/span><\/p>\n<div id=\"attachment_26610\" style=\"width: 381px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/ayushi.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-26610\" class=\"wp-image-26610 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/ayushi.jpg\" alt=\"Python Slice\" width=\"371\" height=\"176\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/ayushi.jpg 371w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/ayushi-150x71.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/ayushi-300x142.jpg 300w\" sizes=\"auto, (max-width: 371px) 100vw, 371px\" \/><\/a><p id=\"caption-attachment-26610\" class=\"wp-caption-text\">Python String\u00a0Slice<\/p><\/div>\n<p><span style=\"font-weight: 400\">We index everything from letters to digits and from spaces to characters.<\/span><\/p>\n<h3>Python Slicing Tuples<\/h3>\n<p><span style=\"font-weight: 400\">Now, let\u2019s take a look at performing Python Slicing on tuples. Check the following code:<\/span><\/p>\n<p><strong>Positive Indices-<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; t=(1,2,3,4,5)\r\n&gt;&gt;&gt; t[slice(2,4)]<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">(3, 4)<\/div>\n<p><strong>Negative Indices-<\/strong><\/p>\n<p><span style=\"font-weight: 400\">Let\u2019s traverse right to left.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; t[slice(-1,-5,-2)]<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">(5, 3)<\/div>\n<h3>Indexing to Create Python Slice<\/h3>\n<p><span style=\"font-weight: 400\">We have often sliced lists using [:]. Let\u2019s try that one more time.<\/span><\/p>\n<div id=\"attachment_26609\" style=\"width: 1091px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Indexing-to-Create-Python-Slice-01.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-26609\" class=\"wp-image-26609 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Indexing-to-Create-Python-Slice-01.jpg\" alt=\"Python Slice\" width=\"1081\" height=\"1081\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Indexing-to-Create-Python-Slice-01.jpg 1081w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Indexing-to-Create-Python-Slice-01-150x150.jpg 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Indexing-to-Create-Python-Slice-01-300x300.jpg 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Indexing-to-Create-Python-Slice-01-768x768.jpg 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Indexing-to-Create-Python-Slice-01-1024x1024.jpg 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Indexing-to-Create-Python-Slice-01-100x100.jpg 100w\" sizes=\"auto, (max-width: 1081px) 100vw, 1081px\" \/><\/a><p id=\"caption-attachment-26609\" class=\"wp-caption-text\">Indexing to Create Python Slicing<\/p><\/div>\n<p><span style=\"font-weight: 400\">Remember the previous Python Slicing example? Now take a look at this-<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; t[-1:-5:-2]<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">(5, 3)<\/div>\n<p><span style=\"font-weight: 400\">So we concur that slicing is a way to choose indices for elements to show. <\/span><\/p>\n<p><span style=\"font-weight: 400\">What slice() really does is give us indices for those. We can use the slice() function as a subscript.<\/span><\/p>\n<p><span style=\"font-weight: 400\">When indexing, what happens when we do not pass one or more of the values?<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; t[:3]    #From 0 to 2<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">(1, 2, 3)<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; t[3:]    #From 3 to end<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">(4, 5)<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; t[:]    #From beginning to end<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">(1, 2, 3, 4, 5)<\/div>\n<h4>1. Extended Python Slices with a step value<\/h4>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; t[::-1]    #Reverse<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">(5, 4, 3, 2, 1)<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; t[::-2]    #Reverse with step=2<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">(5, 3, 1)<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; t[:5:2]    #Upto index 5, with step=2<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">(1, 3, 5)<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; t[:5:-1]    #Index 5 to end (already ahead of that), right to left; results in empty tuple<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">()<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; t<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">(1, 2, 3, 4, 5)<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; t[len(t)::-3]    #End to front, step=3 right to left<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">(5, 2)<\/div>\n<h4>2. Resizing Lists in Python Slices<\/h4>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; l=[1,2,3,4,5]\r\n&gt;&gt;&gt; l[1:4]<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[2, 3, 4]<\/div>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; l[1:4]=[2,3,3.5,4]\r\n&gt;&gt;&gt; l<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[1, 2, 3, 3.5, 4, 5]<\/div>\n<p><span style=\"font-weight: 400\">The length of the slice on the right should be equal to that on the left.<\/span><\/p>\n<h4>3. Deleting Python Slices<\/h4>\n<p><span style=\"font-weight: 400\">We can also use the del keyword to delete a slice.<\/span><\/p>\n<pre class=\"EnlighterJSRAW\">&gt;&gt;&gt; del l[::4]\r\n&gt;&gt;&gt; l<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">[2, 3, 3.5, 5]<\/div>\n<p>So, this was all in Python Slice. Hope you like our explanation.<\/p>\n<h3>Python Interview Questions on Slice Constructor<\/h3>\n<ol>\n<li>What is slicing in Python? Explain with an example.<\/li>\n<li>How do you slice in Python?<\/li>\n<li>What is the slicing operator in Python?<\/li>\n<li>Can you slice a tuple in Python?<\/li>\n<li>How does Python slicing work?<\/li>\n<\/ol>\n<h3>Conclusion<\/h3>\n<p><span style=\"font-weight: 400\">Hence, in this Python Slice Tutorial, we saw the meaning of Slicing in Python.\u00a0 <\/span><span style=\"font-weight: 400\">Moreover, we discussed the Python Slice() object and the Python Slice function. <\/span><\/p>\n<p><span style=\"font-weight: 400\">Also, we learned about Python Slice String.\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Today, in this Python Tutorial, we will discuss Python Slice. First, we will see the meaning of Slicing in Python. Moreover, we will learn Python Slice() function with syntax and example. Also, we will&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":26608,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[4323,6686,10840,10841,10842,10843,10844,10864,12949,14031,15872],"class_list":["post-26604","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-example-of-python-slice","tag-indexing-to-create-python-slice","tag-python-slice","tag-python-slice-object","tag-python-slice-string","tag-python-slice-function","tag-python-slicing-tuples","tag-python-string-slice","tag-slicing-in-python","tag-syntac-of-python-slice","tag-what-is-python-slicing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Slice Constructor - Python Slice String &amp; Slicing Tuple - DataFlair<\/title>\n<meta name=\"description\" content=\"Slicing is useful as it lets us choose what to see and focus on. Let&#039;s learn the Python Slice() function with syntax and an example.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-slice\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Slice Constructor - Python Slice String &amp; Slicing Tuple - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Slicing is useful as it lets us choose what to see and focus on. Let&#039;s learn the Python Slice() function with syntax and an example.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-slice\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-08-29T00:15:01+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-25T08:57:10+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Slice-01.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Slice Constructor - Python Slice String &amp; Slicing Tuple - DataFlair","description":"Slicing is useful as it lets us choose what to see and focus on. Let's learn the Python Slice() function with syntax and an example.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-slice\/","og_locale":"en_US","og_type":"article","og_title":"Python Slice Constructor - Python Slice String &amp; Slicing Tuple - DataFlair","og_description":"Slicing is useful as it lets us choose what to see and focus on. Let's learn the Python Slice() function with syntax and an example.","og_url":"https:\/\/data-flair.training\/blogs\/python-slice\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-08-29T00:15:01+00:00","article_modified_time":"2026-04-25T08:57:10+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Slice-01.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-slice\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-slice\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python Slice Constructor &#8211; Python Slice String &amp; Slicing Tuple","datePublished":"2018-08-29T00:15:01+00:00","dateModified":"2026-04-25T08:57:10+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-slice\/"},"wordCount":797,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-slice\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Slice-01.jpg","keywords":["Example of Python Slice","Indexing to Create Python Slice","Python slice","Python Slice Object","Python Slice String","Python Slice() Function","Python Slicing Tuples","Python String Slice","Slicing in Python","Syntac of Python Slice","What is Python Slicing"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-slice\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-slice\/","url":"https:\/\/data-flair.training\/blogs\/python-slice\/","name":"Python Slice Constructor - Python Slice String &amp; Slicing Tuple - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-slice\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-slice\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Slice-01.jpg","datePublished":"2018-08-29T00:15:01+00:00","dateModified":"2026-04-25T08:57:10+00:00","description":"Slicing is useful as it lets us choose what to see and focus on. Let's learn the Python Slice() function with syntax and an example.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-slice\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-slice\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-slice\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Slice-01.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/08\/Python-Slice-01.jpg","width":1200,"height":628,"caption":"Python Slice | Python Slice() Constructor"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-slice\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Slice Constructor &#8211; Python Slice String &amp; Slicing Tuple"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/26604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=26604"}],"version-history":[{"count":13,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/26604\/revisions"}],"predecessor-version":[{"id":147893,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/26604\/revisions\/147893"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/26608"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=26604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=26604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=26604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}