{"id":3478,"date":"2021-04-23T10:50:45","date_gmt":"2021-04-23T05:20:45","guid":{"rendered":"https:\/\/python-programs.com\/?p=3478"},"modified":"2021-11-22T18:39:21","modified_gmt":"2021-11-22T13:09:21","slug":"python-programming-deleting-list-elements","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/","title":{"rendered":"Python Programming \u2013 Deleting List Elements"},"content":{"rendered":"

In this Page, We are Providing Python Programming \u2013 Deleting List Elements. Students can visit for more Detail and Explanation of Python Handwritten Notes<\/a>\u00a0Pdf.<\/p>\n

Python Programming \u2013 Deleting List Elements<\/h2>\n

Deleting list elements<\/strong><\/p>\n

To remove a list element, one can use either the del statement (if you know the element index to delete) or remove () method (if you do not know the element index, but the element itself, discussed in section 4.1.9). The following example depicts the deletion of an element using the del statement.<\/p>\n

>>> a= [ ' spam ' , ' eggs ' , 100 , 1234 ]\r\n>>> del a [ 1 ]\r\n>>> a\r\n[ ' spam ' , 100 , 1234 ]<\/pre>\n

The del statement can also be used to explicitly remove the entire list.<\/p>\n

>>> a= [ ' spam ' , ' eggs ' , 100 , 1234 ]\r\n>>> del a \r\n>>> a\r\nTraceback ( most recent call last ) :\r\nFile \" <stdin> \" , line 1 , in <module>\r\nNameError: name ' a ' is not defined<\/pre>\n

The following is an interesting case of the del statement:<\/p>\n

>>> a= [ ' spam ' , ' eggs ' , 100 , 1234 ]\r\n>>> del a [ 1 ] , a [ 1 ]\r\n>>> a\r\n[ ' spam ' , 1234 ]<\/pre>\n

It should be noted that the same index is deleted twice. As soon as an element is deleted, the indices of succeeding elements are changed. So deleting an index element n times, would actually delete n elements.<\/p>\n

It is also possible to delete multiple items from a list.<\/p>\n

>>> a= [ ' spam ' , ' eggs ' , 100 , 1234 ]\r\n>>> a [ 1 : 3 ] = [ ]\r\n>>> a\r\n[ ' spam ' , 1234 ]<\/pre>\n

Swapping lists<\/strong><\/p>\n

There might be a scenario in which multiple lists need to be swapped among themselves. This is can done easily using multiple assignments expression.<\/p>\n

>>> a= [ 10 , 20 , 30 ] \r\n>>> b= [ 40 , 50 , 60 ] \r\n>>> c= [ 70 , 80 , 90 ]\r\n>>> a , b , c=c , a , b \r\n>>> a\r\n[ 70 , 80 , 90 ] \r\n>>> b\r\n[ 10 , 20 , 30 ]\r\n>>> c\r\n[ 40 , 50 , 60 ]<\/pre>\n","protected":false},"excerpt":{"rendered":"

In this Page, We are Providing Python Programming \u2013 Deleting List Elements. Students can visit for more Detail and Explanation of Python Handwritten Notes\u00a0Pdf. Python Programming \u2013 Deleting List Elements Deleting list elements To remove a list element, one can use either the del statement (if you know the element index to delete) or remove …<\/p>\n

Python Programming \u2013 Deleting List Elements<\/span> Read More »<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[5],"tags":[],"yoast_head":"\nPython Programming \u2013 Deleting List Elements - Python Programs<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Programming \u2013 Deleting List Elements - Python Programs\" \/>\n<meta property=\"og:description\" content=\"In this Page, We are Providing Python Programming \u2013 Deleting List Elements. Students can visit for more Detail and Explanation of Python Handwritten Notes\u00a0Pdf. Python Programming \u2013 Deleting List Elements Deleting list elements To remove a list element, one can use either the del statement (if you know the element index to delete) or remove … Python Programming \u2013 Deleting List Elements Read More »\" \/>\n<meta property=\"og:url\" content=\"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Programs\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/btechgeeks\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-23T05:20:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-11-22T13:09:21+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@btech_geeks\" \/>\n<meta name=\"twitter:site\" content=\"@btech_geeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prasanna\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https:\/\/python-programs.com\/#organization\",\"name\":\"BTech Geeks\",\"url\":\"https:\/\/python-programs.com\/\",\"sameAs\":[\"https:\/\/www.instagram.com\/btechgeeks\/\",\"https:\/\/www.linkedin.com\/in\/btechgeeks\",\"https:\/\/in.pinterest.com\/btechgeek\/\",\"https:\/\/www.youtube.com\/channel\/UC9MlCqdJ3lKqz2p5114SDIg\",\"https:\/\/www.facebook.com\/btechgeeks\",\"https:\/\/twitter.com\/btech_geeks\"],\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/python-programs.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/python-programs.com\/wp-content\/uploads\/2020\/11\/BTechGeeks.png\",\"contentUrl\":\"https:\/\/python-programs.com\/wp-content\/uploads\/2020\/11\/BTechGeeks.png\",\"width\":350,\"height\":70,\"caption\":\"BTech Geeks\"},\"image\":{\"@id\":\"https:\/\/python-programs.com\/#\/schema\/logo\/image\/\"}},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/python-programs.com\/#website\",\"url\":\"https:\/\/python-programs.com\/\",\"name\":\"Python Programs\",\"description\":\"Python Programs with Examples, How To Guides on Python\",\"publisher\":{\"@id\":\"https:\/\/python-programs.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/python-programs.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/#webpage\",\"url\":\"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/\",\"name\":\"Python Programming \u2013 Deleting List Elements - Python Programs\",\"isPartOf\":{\"@id\":\"https:\/\/python-programs.com\/#website\"},\"datePublished\":\"2021-04-23T05:20:45+00:00\",\"dateModified\":\"2021-11-22T13:09:21+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/python-programs.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python Programming \u2013 Deleting List Elements\"}]},{\"@type\":\"Article\",\"@id\":\"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/#webpage\"},\"author\":{\"@id\":\"https:\/\/python-programs.com\/#\/schema\/person\/ea8ce699662f0d7e248e52fe080b85bb\"},\"headline\":\"Python Programming \u2013 Deleting List Elements\",\"datePublished\":\"2021-04-23T05:20:45+00:00\",\"dateModified\":\"2021-11-22T13:09:21+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/#webpage\"},\"wordCount\":185,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/python-programs.com\/#organization\"},\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/#respond\"]}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/python-programs.com\/#\/schema\/person\/ea8ce699662f0d7e248e52fe080b85bb\",\"name\":\"Prasanna\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/python-programs.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/174540ad43736c7d1a4c4f83c775e74d?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/174540ad43736c7d1a4c4f83c775e74d?s=96&d=mm&r=g\",\"caption\":\"Prasanna\"},\"url\":\"https:\/\/python-programs.com\/author\/prasanna\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Programming \u2013 Deleting List Elements - Python Programs","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:\/\/python-programs.com\/python-programming-deleting-list-elements\/","og_locale":"en_US","og_type":"article","og_title":"Python Programming \u2013 Deleting List Elements - Python Programs","og_description":"In this Page, We are Providing Python Programming \u2013 Deleting List Elements. Students can visit for more Detail and Explanation of Python Handwritten Notes\u00a0Pdf. Python Programming \u2013 Deleting List Elements Deleting list elements To remove a list element, one can use either the del statement (if you know the element index to delete) or remove … Python Programming \u2013 Deleting List Elements Read More »","og_url":"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/","og_site_name":"Python Programs","article_publisher":"https:\/\/www.facebook.com\/btechgeeks","article_published_time":"2021-04-23T05:20:45+00:00","article_modified_time":"2021-11-22T13:09:21+00:00","twitter_card":"summary_large_image","twitter_creator":"@btech_geeks","twitter_site":"@btech_geeks","twitter_misc":{"Written by":"Prasanna","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Organization","@id":"https:\/\/python-programs.com\/#organization","name":"BTech Geeks","url":"https:\/\/python-programs.com\/","sameAs":["https:\/\/www.instagram.com\/btechgeeks\/","https:\/\/www.linkedin.com\/in\/btechgeeks","https:\/\/in.pinterest.com\/btechgeek\/","https:\/\/www.youtube.com\/channel\/UC9MlCqdJ3lKqz2p5114SDIg","https:\/\/www.facebook.com\/btechgeeks","https:\/\/twitter.com\/btech_geeks"],"logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/python-programs.com\/#\/schema\/logo\/image\/","url":"https:\/\/python-programs.com\/wp-content\/uploads\/2020\/11\/BTechGeeks.png","contentUrl":"https:\/\/python-programs.com\/wp-content\/uploads\/2020\/11\/BTechGeeks.png","width":350,"height":70,"caption":"BTech Geeks"},"image":{"@id":"https:\/\/python-programs.com\/#\/schema\/logo\/image\/"}},{"@type":"WebSite","@id":"https:\/\/python-programs.com\/#website","url":"https:\/\/python-programs.com\/","name":"Python Programs","description":"Python Programs with Examples, How To Guides on Python","publisher":{"@id":"https:\/\/python-programs.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/python-programs.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/#webpage","url":"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/","name":"Python Programming \u2013 Deleting List Elements - Python Programs","isPartOf":{"@id":"https:\/\/python-programs.com\/#website"},"datePublished":"2021-04-23T05:20:45+00:00","dateModified":"2021-11-22T13:09:21+00:00","breadcrumb":{"@id":"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/python-programs.com\/python-programming-deleting-list-elements\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/python-programs.com\/"},{"@type":"ListItem","position":2,"name":"Python Programming \u2013 Deleting List Elements"}]},{"@type":"Article","@id":"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/#article","isPartOf":{"@id":"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/#webpage"},"author":{"@id":"https:\/\/python-programs.com\/#\/schema\/person\/ea8ce699662f0d7e248e52fe080b85bb"},"headline":"Python Programming \u2013 Deleting List Elements","datePublished":"2021-04-23T05:20:45+00:00","dateModified":"2021-11-22T13:09:21+00:00","mainEntityOfPage":{"@id":"https:\/\/python-programs.com\/python-programming-deleting-list-elements\/#webpage"},"wordCount":185,"commentCount":0,"publisher":{"@id":"https:\/\/python-programs.com\/#organization"},"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/python-programs.com\/python-programming-deleting-list-elements\/#respond"]}]},{"@type":"Person","@id":"https:\/\/python-programs.com\/#\/schema\/person\/ea8ce699662f0d7e248e52fe080b85bb","name":"Prasanna","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/python-programs.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/174540ad43736c7d1a4c4f83c775e74d?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/174540ad43736c7d1a4c4f83c775e74d?s=96&d=mm&r=g","caption":"Prasanna"},"url":"https:\/\/python-programs.com\/author\/prasanna\/"}]}},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/posts\/3478"}],"collection":[{"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/comments?post=3478"}],"version-history":[{"count":1,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/posts\/3478\/revisions"}],"predecessor-version":[{"id":3480,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/posts\/3478\/revisions\/3480"}],"wp:attachment":[{"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/media?parent=3478"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/categories?post=3478"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/python-programs.com\/wp-json\/wp\/v2\/tags?post=3478"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}