{"id":18253,"date":"2021-11-11T12:11:26","date_gmt":"2021-11-11T06:41:26","guid":{"rendered":"https:\/\/tutorial.eyehunts.com\/?p=18253"},"modified":"2023-03-15T17:52:48","modified_gmt":"2023-03-15T12:22:48","slug":"del-list-python-example-code","status":"publish","type":"post","link":"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/","title":{"rendered":"del list Python | Example code"},"content":{"rendered":"\n<p>Using the del keyword can delete list objects in Python. It will delete the whole list.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>del thislist<\/code><\/pre>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example del list Python<\/strong><\/h2>\n\n\n\n<p>Simple example code print list after deleted it.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>this_list = &#91;\"apple\", \"banana\", \"cherry\"]\n\ndel this_list\n\nprint(this_list)<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"427\" height=\"183\" src=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/del-list-Python.jpg?resize=427%2C183&#038;ssl=1\" alt=\"del list Python\" class=\"wp-image-22066\"\/><\/figure><\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>You can also <a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-list-remove-function-remove-elements-by-value\/\">remove elements<\/a> from a list with <code>del<\/code> statements. Just pass the index value inside the brackets [].<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>l = list(range(6))\nprint(l)\n\ndel l&#91;0]\nprint(l)\n<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>:<\/p>\n\n\n\n<p>[0, 1, 2, 3, 4, 5]<br>[1, 2, 3, 4, 5]<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Do comment if you have any doubts or suggestions on this Python list topic.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong> IDE:&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.jetbrains.com\/pycharm\/\" target=\"_blank\">PyCharm<\/a>&nbsp;2021.3.3 (Community Edition)<\/p><p>Windows 10<\/p><p><strong>Python 3.10.1<\/strong><\/p><p>All<strong>&nbsp;Python Examples&nbsp;are in&nbsp;Python&nbsp;3<\/strong>, so Maybe its different from python 2 or upgraded versions.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Using the del keyword can delete list objects in Python. It will delete the whole list. Example del list Python Simple example code print list after deleted it. Output: You can also remove elements from a list with del statements. Just pass the index value inside the brackets []. Output: [0, 1, 2, 3, 4,&hellip;&nbsp;<a href=\"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">del list Python | Example code<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[30],"tags":[172,83],"post_series":[],"class_list":["post-18253","post","type-post","status-publish","format-standard","hentry","category-python","tag-python-del","tag-python-list"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>del list Python | Code<\/title>\n<meta name=\"description\" content=\"Using the del keyword can delete list objects in Python. It will delete the whole list. Simple example code print list after deleted it.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"del list Python | Code\" \/>\n<meta property=\"og:description\" content=\"Using the del keyword can delete list objects in Python. It will delete the whole list. Simple example code print list after deleted it.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2021-11-11T06:41:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-03-15T12:22:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/del-list-Python.jpg\" \/>\n<meta name=\"author\" content=\"Rohit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rohit\" \/>\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:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/\",\"name\":\"del list Python | Code\",\"isPartOf\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/del-list-Python.jpg\",\"datePublished\":\"2021-11-11T06:41:26+00:00\",\"dateModified\":\"2023-03-15T12:22:48+00:00\",\"author\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\"},\"description\":\"Using the del keyword can delete list objects in Python. It will delete the whole list. Simple example code print list after deleted it.\",\"breadcrumb\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/del-list-Python.jpg?fit=427%2C183&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/del-list-Python.jpg?fit=427%2C183&ssl=1\",\"width\":427,\"height\":183},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tutorial.eyehunts.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"del list Python | Example code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\",\"url\":\"https:\/\/tutorial.eyehunts.com\/\",\"name\":\"Tutorial\",\"description\":\"By EyeHunts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\",\"name\":\"Rohit\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"contentUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"caption\":\"Rohit\"},\"description\":\"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.\",\"url\":\"https:\/\/tutorial.eyehunts.com\/author\/rohit\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"del list Python | Code","description":"Using the del keyword can delete list objects in Python. It will delete the whole list. Simple example code print list after deleted it.","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:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/","og_locale":"en_US","og_type":"article","og_title":"del list Python | Code","og_description":"Using the del keyword can delete list objects in Python. It will delete the whole list. Simple example code print list after deleted it.","og_url":"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/","og_site_name":"Tutorial","article_published_time":"2021-11-11T06:41:26+00:00","article_modified_time":"2023-03-15T12:22:48+00:00","og_image":[{"url":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/del-list-Python.jpg","type":"","width":"","height":""}],"author":"Rohit","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rohit","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/","url":"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/","name":"del list Python | Code","isPartOf":{"@id":"https:\/\/tutorial.eyehunts.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/#primaryimage"},"image":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/#primaryimage"},"thumbnailUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/del-list-Python.jpg","datePublished":"2021-11-11T06:41:26+00:00","dateModified":"2023-03-15T12:22:48+00:00","author":{"@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1"},"description":"Using the del keyword can delete list objects in Python. It will delete the whole list. Simple example code print list after deleted it.","breadcrumb":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/#primaryimage","url":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/del-list-Python.jpg?fit=427%2C183&ssl=1","contentUrl":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/del-list-Python.jpg?fit=427%2C183&ssl=1","width":427,"height":183},{"@type":"BreadcrumbList","@id":"https:\/\/tutorial.eyehunts.com\/python\/del-list-python-example-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tutorial.eyehunts.com\/"},{"@type":"ListItem","position":2,"name":"del list Python | Example code"}]},{"@type":"WebSite","@id":"https:\/\/tutorial.eyehunts.com\/#website","url":"https:\/\/tutorial.eyehunts.com\/","name":"Tutorial","description":"By EyeHunts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1","name":"Rohit","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/","url":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","contentUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","caption":"Rohit"},"description":"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.","url":"https:\/\/tutorial.eyehunts.com\/author\/rohit\/"}]}},"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":22137,"url":"https:\/\/tutorial.eyehunts.com\/python\/remove-all-elements-from-the-list-python-example-code\/","url_meta":{"origin":18253,"position":0},"title":"Remove all elements from the list Python | Example code","author":"Rohit","date":"November 12, 2021","format":false,"excerpt":"Use the clear() function to remove all elements from the list in Python. You can also use the Slice assignment to empty the list by replacing all the elements with an empty list. Using the del statement will delete the whole list object. This useful Python trick will come in\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Remove all elements from the list Python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/11\/Remove-all-elements-from-the-list-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":18244,"url":"https:\/\/tutorial.eyehunts.com\/python\/remove-element-from-list-python-by-index-example-code\/","url_meta":{"origin":18253,"position":1},"title":"Remove element from list Python by index | Example code","author":"Rohit","date":"August 19, 2021","format":false,"excerpt":"Use pop() method or del keyword to remove an element from list python by index. The pop() is useful to remove and keep an item from a list. Where del actually trashes the item. Example remove an element from a list by index in Python Simple example code. Using pop()\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Remove element from list Python by index","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Remove-element-from-list-Python-by-index.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":20590,"url":"https:\/\/tutorial.eyehunts.com\/python\/del-function-in-python-code\/","url_meta":{"origin":18253,"position":2},"title":"del function in Python | Code","author":"Rohit","date":"October 13, 2021","format":false,"excerpt":"Python has a del statement (keyword) to delete objects, not a del function. The del keyword is used to delete a list, or dictionaries, remove key-value pairs from a dictionary, delete variables, etc. del object_name Let's see del examples Delete Variables, the item from the list, and key-value from a\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/del-function-in-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":18242,"url":"https:\/\/tutorial.eyehunts.com\/python\/del-keyword-in-python-example-code\/","url_meta":{"origin":18253,"position":3},"title":"del keyword in Python | Example code","author":"Rohit","date":"August 20, 2021","format":false,"excerpt":"Python del keyword is used to delete objects. It could delete everything from an object like variables, lists, dictionaries, slice a list, etc. del object_name Examples del keyword in Python Simple example code to delete variables, lists, dictionaries, and class objects. Deleting variables Delete both the variables num = 10\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"del keyword in Python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/del-keyword-in-Python-1.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":17864,"url":"https:\/\/tutorial.eyehunts.com\/python\/remove-last-character-from-list-python-example-code\/","url_meta":{"origin":18253,"position":4},"title":"Remove last character from list Python | Example code","author":"Rohit","date":"August 16, 2021","format":false,"excerpt":"The slice notation [:-1] is the right approach to remove the last character from the list python. You can also use the pop() and del function to delete the last value-form list. Example remove the last element from a Python list Simple example code. Using Slicing Slice operation returns a\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Remove last character from list python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Remove-last-character-from-list-python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":18265,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-list-without-last-element-example-code\/","url_meta":{"origin":18253,"position":5},"title":"Python list without last element | Example code","author":"Rohit","date":"August 24, 2021","format":false,"excerpt":"You can go through the list without the last element or remove the last element from the list in Python. Python list without last element examples Simple example code. Go through the list without the last element in Python Simply use slice notation to skip the last element from the\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python list without last element","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/08\/Python-list-without-last-element.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/18253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/comments?post=18253"}],"version-history":[{"count":1,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/18253\/revisions"}],"predecessor-version":[{"id":36975,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/18253\/revisions\/36975"}],"wp:attachment":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/media?parent=18253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/categories?post=18253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/tags?post=18253"},{"taxonomy":"post_series","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/post_series?post=18253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}