{"id":14233,"date":"2022-01-21T11:59:12","date_gmt":"2022-01-21T11:59:12","guid":{"rendered":"https:\/\/linuxways.net\/?p=14233"},"modified":"2022-01-21T11:59:12","modified_gmt":"2022-01-21T11:59:12","slug":"python-list-pop-method","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/scripting\/python-list-pop-method\/","title":{"rendered":"Python List pop() Method"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>The pop() list is a built-in Python method that deletes an element by a specified position. It will print out a new list without the deleted elements. If you don&#8217;t specify the position, it will remove the last element. If you specify a position out of range, it will return IndexError.<\/p>\n<p>Now we&#8217;re gonna teach you to use the pop() method in Python.<\/p>\n<h2>Example<\/h2>\n<pre>list = [1, 2, 3, 4]\r\n\r\nlist.pop(1)\r\n\r\nprint(list)<\/pre>\n<p>Output:<\/p>\n<p><strong>[1, 3, 4]<\/strong><\/p>\n<h2>Definition<\/h2>\n<p>The list pop() method will remove the element at the position you want to remove.<\/p>\n<p>If you don&#8217;t specify the position, it will remove the last element.<\/p>\n<h2>The syntax<\/h2>\n<pre>list.pop(pos)<\/pre>\n<p><strong>Parameter Values<\/strong>:<\/p>\n<p>pos: the position you want to remove<\/p>\n<h2>More examples<\/h2>\n<p><strong>Example 1<\/strong>: Remove the last element<\/p>\n<pre>list = [1, 2, 3, 4]\r\n\r\nlist.pop()\r\n\r\nprint(list)<\/pre>\n<p>Output:<\/p>\n<p><strong>[1, 2, 3]<\/strong><\/p>\n<p><strong>Example 2<\/strong>: Remove the first element<\/p>\n<pre>list = [1, 2, 3, 4]<\/pre>\n<p>#I remove the 1st element<\/p>\n<pre>list.pop(0)\r\n\r\nprint(list)<\/pre>\n<p>Output:<\/p>\n<p><strong>[2, 3, 4]<\/strong><\/p>\n<p><strong>Example 3<\/strong>: IndexError<\/p>\n<pre>list = [1, 2, 3, 4]\r\n\r\nlist.pop(5)\r\n\r\nprint(list)<\/pre>\n<p>Output:<\/p>\n<p><strong>IndexError: pop index out of range<\/strong><\/p>\n<h2>Conclusion<\/h2>\n<p>We just taught you to use the pop() method in Python.<\/p>\n<p>Thank you for referring!<\/p>","protected":false},"excerpt":{"rendered":"<p>Introduction The pop() list is a built-in Python method that deletes an element by a specified position. It will print out a new list without the deleted elements.&hellip;<\/p>","protected":false},"author":1,"featured_media":14259,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[168],"tags":[870,10],"class_list":["post-14233","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-pop","tag-python"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/14233","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=14233"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/14233\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/14259"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=14233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=14233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=14233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}