{"id":3279,"date":"2022-11-14T20:07:10","date_gmt":"2022-11-14T20:07:10","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=3279"},"modified":"2022-11-14T20:07:12","modified_gmt":"2022-11-14T20:07:12","slug":"python-list-reverse","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/python-list-reverse\/","title":{"rendered":"Python List reverse() Method"},"content":{"rendered":"<p style=\"text-align: center;\">Python List reverse<\/p>\n<p>At times, when we are required to reverse our list, we can do it with the help of the reverse method. As the name suggests, the reverse method is going to reverse the list for us. This method does not return anything, and it does not take any arguments. It just updates the current list. Let\u2019s have a look at a simple program, which demonstrates to us the reverse method &#8211;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3280 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-reverse-METHOD-IN-PYTHON.jpg\" alt=\"\" width=\"906\" height=\"118\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-reverse-METHOD-IN-PYTHON.jpg 906w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-reverse-METHOD-IN-PYTHON-300x39.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-reverse-METHOD-IN-PYTHON-768x100.jpg 768w\" sizes=\"auto, (max-width: 906px) 100vw, 906px\" \/><\/p>\n<h2 style=\"text-align: center;\">Python List reverse() Method<\/h2>\n<p>As you can see in the above program, we have a simple list, and then we are trying to use the reverse method on the list. After that, we are printing our list, and we can see in the output, that the list is reversed. Let\u2019s have a look at the output now -0<\/p>\n<p>[31, 15, 29, 45, 12, 23]<\/p>\n<p>As you can see, we have got our list reversed. So, whenever we need to reverse our list, we can make use of the reverse method. Alternatively, we can also do list slicing, to reverse a list. Let\u2019s have a look at that as well. We simply need to omit the start and stop values, and then we have to provide the step as -1. Doing this will simply reverse the list. Let\u2019s have a look at the program.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3281 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-reverse-METHOD-IN-PYTHON-1.jpg\" alt=\"\" width=\"891\" height=\"133\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-reverse-METHOD-IN-PYTHON-1.jpg 891w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-reverse-METHOD-IN-PYTHON-1-300x45.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-reverse-METHOD-IN-PYTHON-1-768x115.jpg 768w\" sizes=\"auto, (max-width: 891px) 100vw, 891px\" \/><\/p>\n<p>As you can see, we are using the slicing operator, to reverse the list. Reversing a list is very simple, and useful at times. We would use the reverse method as and when required in our Python programs. Remember that the reverse method reverses the list.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python List reverse At times, when we are required to reverse our list, we can do it with the help of the reverse method. As the name suggests, the reverse method is going to reverse the list for us. This method does not return anything, and it does not take any arguments. It just updates [&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-3279","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\/3279","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=3279"}],"version-history":[{"count":2,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3279\/revisions"}],"predecessor-version":[{"id":4080,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3279\/revisions\/4080"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=3279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=3279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=3279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}