{"id":3257,"date":"2022-11-14T19:36:56","date_gmt":"2022-11-14T19:36:56","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=3257"},"modified":"2022-11-14T19:36:58","modified_gmt":"2022-11-14T19:36:58","slug":"python-list-clear","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/python-list-clear\/","title":{"rendered":"Python List clear() Method"},"content":{"rendered":"<p style=\"text-align: center;\">Python List clear<\/p>\n<p>Now, we are going to learn about the clear method. As the name of the method says, this method removes all the items from the list. Let\u2019s have a look at a simple program, which tries to demonstrate the clear method &#8211;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3258 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-clear-METHOD-IN-PYTHON.jpg\" alt=\"\" width=\"892\" height=\"132\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-clear-METHOD-IN-PYTHON.jpg 892w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-clear-METHOD-IN-PYTHON-300x44.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-clear-METHOD-IN-PYTHON-768x114.jpg 768w\" sizes=\"auto, (max-width: 892px) 100vw, 892px\" \/><\/p>\n<h2 style=\"text-align: center;\">Python List clear<\/h2>\n<p>As you can see in the above program, we have a list, with some numbers, and then we are trying to use the clear method on the list. The clear method removes all the elements from the list, and when we are printing the list, it is simply empty. You can also check the output of the above program.<\/p>\n<p>Alternatively, you can also use the del keyword to empty the list. Have a look at the below program, which demonstrates using the del keyword to empty the list.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3260 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-clear-METHOD-IN-PYTHON-1-1.jpg\" alt=\"\" width=\"884\" height=\"129\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-clear-METHOD-IN-PYTHON-1-1.jpg 884w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-clear-METHOD-IN-PYTHON-1-1-300x44.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-clear-METHOD-IN-PYTHON-1-1-768x112.jpg 768w\" sizes=\"auto, (max-width: 884px) 100vw, 884px\" \/><\/p>\n<p>As you can see, we have made use of the del keyword, to clear the list. You can observe the output of this program as well, and you will find that the list that we get is empty list. So, we can make use of the clear method, as and when required in our python programs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python List clear Now, we are going to learn about the clear method. As the name of the method says, this method removes all the items from the list. Let\u2019s have a look at a simple program, which tries to demonstrate the clear method &#8211; Python List clear As you can see in the above [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[26,27],"class_list":{"0":"post-3257","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python-tutorial","7":"tag-python","8":"tag-python-tutorial"},"_links":{"self":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3257","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/comments?post=3257"}],"version-history":[{"count":2,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3257\/revisions"}],"predecessor-version":[{"id":4076,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3257\/revisions\/4076"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=3257"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=3257"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=3257"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}