{"id":3254,"date":"2022-11-14T19:18:15","date_gmt":"2022-11-14T19:18:15","guid":{"rendered":"https:\/\/gyanipandit.com\/programming\/?p=3254"},"modified":"2022-11-14T19:18:17","modified_gmt":"2022-11-14T19:18:17","slug":"python-list-insert","status":"publish","type":"post","link":"https:\/\/gyanipandit.com\/programming\/python-list-insert\/","title":{"rendered":"Python List insert() Method"},"content":{"rendered":"<p style=\"text-align: center;\">Python List insert() Method<\/p>\n<p>Now, we are going to discuss the insert method. As the name suggests, the insert method is going to help us insert some elements at the specified index. This method takes in two arguments, in which, the first argument is the position where we want to insert the element, and the second argument is the element that needs to be inserted at that position. Let\u2019s have a look at a simple program, which demonstrates the insert method.<\/p>\n<h2 style=\"text-align: center;\">Python List insert<\/h2>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-3255 size-full\" src=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-insert-METHOD-IN-PYTHON.jpg\" alt=\"\" width=\"969\" height=\"139\" srcset=\"https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-insert-METHOD-IN-PYTHON.jpg 969w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-insert-METHOD-IN-PYTHON-300x43.jpg 300w, https:\/\/gyanipandit.com\/programming\/wp-content\/uploads\/2022\/10\/THE-insert-METHOD-IN-PYTHON-768x110.jpg 768w\" sizes=\"auto, (max-width: 969px) 100vw, 969px\" \/><\/p>\n<p>As you can see in the above program, we have a list, which contains the names of some fruits, and then we are trying to use the insert method on the list. We are giving two arguments to the list, in which the first argument is the position, and the second argument is the element that we want to insert at the specified position. Let\u2019s have a look at the output now &#8211;<\/p>\n<p>[&#8216;Apple&#8217;, &#8216;Orange&#8217;, &#8216;Kiwi&#8217;, &#8216;Guava&#8217;]<\/p>\n<p>As you can see, the string &#8216;Orange&#8217; has been inserted into index 1, and all the other elements are shifted to the right. This method as well returns None, and it updates the current list.<\/p>\n<p>So, this way, we can make use of the insert method, to insert some element at the specified position in the list. We can make use of the insert method, as and when required in our python programs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python List insert() Method Now, we are going to discuss the insert method. As the name suggests, the insert method is going to help us insert some elements at the specified index. This method takes in two arguments, in which, the first argument is the position where we want to insert the element, and the [&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-3254","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\/3254","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=3254"}],"version-history":[{"count":2,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3254\/revisions"}],"predecessor-version":[{"id":4075,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/posts\/3254\/revisions\/4075"}],"wp:attachment":[{"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/media?parent=3254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/categories?post=3254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gyanipandit.com\/programming\/wp-json\/wp\/v2\/tags?post=3254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}