<br />
<b>Warning</b>:  Undefined array key "global_protection_id" in <b>/home/wikitechy/public_html/interview-questions/wp-content/plugins/content-protector/inc/class-ps-rest-handler.php</b> on line <b>51</b><br />
{"id":4698,"date":"2022-08-16T10:31:28","date_gmt":"2022-08-16T10:31:28","guid":{"rendered":"https:\/\/www.wikitechy.com\/interview-questions\/?p=4698"},"modified":"2022-08-16T10:31:28","modified_gmt":"2022-08-16T10:31:28","slug":"what-is-slicing-in-python","status":"publish","type":"post","link":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-slicing-in-python\/","title":{"rendered":"What is slicing in Python ?"},"content":{"rendered":"<ul>\n<li>In python slice () function is used to get a slice of elements from the collection of elements.<\/li>\n<li>It provides two overloaded slice functions there the first takes a single argument while the second function takes three arguments and returns a slice object.<\/li>\n<li>This slice object can be used to get a subsection of the collection.<\/li>\n<li>Start parameter is used to starting index where the slicing of object starts.<\/li>\n<li>Stop parameter is used to ending index where the slicing of objects stops.<\/li>\n<li>Step parameter is an optional argument that determines the increment between each index for slicing.<\/li>\n<li>It returns a sliced object containing elements in the given range only.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><img fetchpriority=\"high\" decoding=\"async\" class=\"size-full wp-image-4699 aligncenter\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-function.png\" alt=\"\" width=\"1012\" height=\"344\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-function.png 1012w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-function-300x102.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-function-768x261.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-function-390x133.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-function-820x279.png 820w\" sizes=\"(max-width: 1012px) 100vw, 1012px\" \/><\/p>\n<h3 id=\"sample-code\"><strong>Sample Code<\/strong><\/h3>\n<div class=\"code-embed-wrapper\"> <div class=\"code-embed-infos\"> <\/div> <pre class=\"language-python code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-python code-embed-code\">#\u00a0Python\u00a0slice()\u00a0function\u00a0example\u00a0\u00a0<br\/><br\/>#\u00a0Calling\u00a0function\u00a0\u00a0<br\/><br\/>tup\u00a0=\u00a0(45,68,955,1214,41,558,636,66)\u00a0\u00a0<br\/><br\/>slic\u00a0=\u00a0slice(0,10,3)\u00a0#\u00a0returns\u00a0slice\u00a0object\u00a0\u00a0<br\/><br\/>slic2\u00a0=\u00a0slice(-1,0,-3)\u00a0#\u00a0returns\u00a0slice\u00a0object\u00a0\u00a0<br\/><br\/>#\u00a0We\u00a0can\u00a0use\u00a0this\u00a0slice\u00a0object\u00a0to\u00a0get\u00a0elements\u00a0\u00a0<br\/><br\/>str2\u00a0=\u00a0tup[slic]\u00a0\u00a0<br\/><br\/>str3\u00a0=\u00a0tup[slic2]\u00a0#\u00a0returns\u00a0elements\u00a0in\u00a0reverse\u00a0order\u00a0\u00a0<br\/><br\/>#\u00a0Displaying\u00a0result\u00a0\u00a0<br\/><br\/>print(str2)\u00a0\u00a0<br\/><br\/>print(str3)<br\/><br\/>\u00a0<\/code><\/pre> <\/div>\n<h3 id=\"output\"><strong>Output<\/strong><\/h3>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-4700\" src=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-method.png\" alt=\"\" width=\"1445\" height=\"160\" srcset=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-method.png 1445w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-method-300x33.png 300w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-method-1024x113.png 1024w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-method-768x85.png 768w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-method-390x43.png 390w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-method-820x91.png 820w, https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-method-1180x131.png 1180w\" sizes=\"(max-width: 1445px) 100vw, 1445px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In python slice () function is used to get a slice of elements from the collection of elements. It provides two overloaded slice functions there the first takes a single argument while the second function takes three arguments and returns a slice object. This slice object can be used to get a subsection of the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"passster_activate_protection":false,"passster_protect_child_pages":"","passster_protection_type":"password","passster_password":"","passster_activate_overwrite_defaults":"","passster_headline":"","passster_instruction":"","passster_placeholder":"","passster_button":"","passster_id":"","passster_activate_misc_settings":"","passster_redirect_url":"","passster_hide":"no","passster_area_shortcode":"","gtb_hide_title":false,"gtb_wrap_title":false,"gtb_class_title":"","gtb_remove_headerfooter":false,"footnotes":""},"categories":[5608],"tags":[18187,18189,18183,18184,18188,18186,18181,18194,18193,18195,18185,18190,18191,18180,18192,18182],"class_list":["post-4698","post","type-post","status-publish","format-standard","hentry","category-python","tag-advance-slicing-in-python","tag-how-slicing-work-in-python","tag-indexing-and-slicing-in-python","tag-negative-slicing-in-python","tag-python-slice-class","tag-slicing-in-set-python","tag-slicing-list-in-python","tag-what-is-indexing-and-slicing-in-python","tag-what-is-list-slicing-in-python","tag-what-is-slicing-and-indexing-in-python-explain-with-an-example","tag-what-is-slicing-in-programming","tag-what-is-slicing-in-python","tag-what-is-slicing-in-python-explain-briefly-about-it","tag-what-is-slicing-in-python-with-example","tag-what-is-string-slicing-in-python","tag-what-is-string-slicing-in-python-with-example"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>What is slicing in Python ? - Python Slice() Function - Slicing in Python<\/title>\n<meta name=\"description\" content=\"What is slicing in Python ? - In python slice () function is used to get a slice of elements from the collection of elements.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-slicing-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is slicing in Python ? - Python Slice() Function - Slicing in Python\" \/>\n<meta property=\"og:description\" content=\"What is slicing in Python ? - In python slice () function is used to get a slice of elements from the collection of elements.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-slicing-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Wikitechy\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-16T10:31:28+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-function.png\" \/>\n<meta name=\"author\" content=\"webmaster\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"webmaster\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-slicing-in-python\/\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-slicing-in-python\/\",\"name\":\"What is slicing in Python ? - Python Slice() Function - Slicing in Python\",\"isPartOf\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-slicing-in-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-slicing-in-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-function.png\",\"datePublished\":\"2022-08-16T10:31:28+00:00\",\"dateModified\":\"2022-08-16T10:31:28+00:00\",\"author\":{\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\"},\"description\":\"What is slicing in Python ? - In python slice () function is used to get a slice of elements from the collection of elements.\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-slicing-in-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-slicing-in-python\/#primaryimage\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-function.png\",\"contentUrl\":\"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-function.png\",\"width\":1012,\"height\":344},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#website\",\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/\",\"name\":\"Wikitechy\",\"description\":\"Interview Questions\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4\",\"name\":\"webmaster\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g\",\"caption\":\"webmaster\"},\"sameAs\":[\"https:\/\/www.wikitechy.com\/interview-questions\"],\"url\":\"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"What is slicing in Python ? - Python Slice() Function - Slicing in Python","description":"What is slicing in Python ? - In python slice () function is used to get a slice of elements from the collection of elements.","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:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-slicing-in-python\/","og_locale":"en_US","og_type":"article","og_title":"What is slicing in Python ? - Python Slice() Function - Slicing in Python","og_description":"What is slicing in Python ? - In python slice () function is used to get a slice of elements from the collection of elements.","og_url":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-slicing-in-python\/","og_site_name":"Wikitechy","article_published_time":"2022-08-16T10:31:28+00:00","og_image":[{"url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-function.png"}],"author":"webmaster","twitter_card":"summary_large_image","twitter_misc":{"Written by":"webmaster","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-slicing-in-python\/","url":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-slicing-in-python\/","name":"What is slicing in Python ? - Python Slice() Function - Slicing in Python","isPartOf":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-slicing-in-python\/#primaryimage"},"image":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-slicing-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-function.png","datePublished":"2022-08-16T10:31:28+00:00","dateModified":"2022-08-16T10:31:28+00:00","author":{"@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4"},"description":"What is slicing in Python ? - In python slice () function is used to get a slice of elements from the collection of elements.","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-slicing-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/python\/what-is-slicing-in-python\/#primaryimage","url":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-function.png","contentUrl":"https:\/\/www.wikitechy.com\/interview-questions\/wp-content\/uploads\/2022\/08\/slicing-function.png","width":1012,"height":344},{"@type":"WebSite","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#website","url":"https:\/\/www.wikitechy.com\/interview-questions\/","name":"Wikitechy","description":"Interview Questions","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wikitechy.com\/interview-questions\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/f785ba3ecc599133e65ab6138042a3e4","name":"webmaster","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.wikitechy.com\/interview-questions\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/155b77fd8cdda3d0913fcb7e7ee63543b0c345d2d8f6dcebda5b0583ab61f967?s=96&d=mm&r=g","caption":"webmaster"},"sameAs":["https:\/\/www.wikitechy.com\/interview-questions"],"url":"https:\/\/www.wikitechy.com\/interview-questions\/author\/webmaster\/"}]}},"_links":{"self":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4698","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/comments?post=4698"}],"version-history":[{"count":1,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4698\/revisions"}],"predecessor-version":[{"id":4701,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/posts\/4698\/revisions\/4701"}],"wp:attachment":[{"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/media?parent=4698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/categories?post=4698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wikitechy.com\/interview-questions\/wp-json\/wp\/v2\/tags?post=4698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}