{"id":520,"date":"2024-10-19T03:31:59","date_gmt":"2024-10-19T03:31:59","guid":{"rendered":"https:\/\/itsmycode.com\/?p=520"},"modified":"2024-10-19T03:31:59","modified_gmt":"2024-10-19T03:31:59","slug":"python-list-append","status":"publish","type":"post","link":"https:\/\/itsmycode.com\/python-list-append\/","title":{"rendered":"Python List append()"},"content":{"rendered":"\n<p>The <strong>append() method <\/strong>in Python adds an element to the end of the list. After appending the new element, the size of the list increases by one.<\/p>\n\n\n\n<p>In this tutorial, we will learn about the <strong>Python list append()<\/strong> method with the help of examples.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"syntax-of-list-append\">Syntax of List append()&nbsp;<\/h2>\n\n\n\n<p>The syntax of the <strong><code>append()<\/code><\/strong> method is:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">list.append(item)<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"append-parameters\">append() Parameters<\/h2>\n\n\n\n<p>The <strong><code>append()<\/code><\/strong> method takes a single parameter.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>item \u2013<\/strong>\u00a0an item to be added at the end of the list. The element can be of any data type such as number, decimal, string, character, list etc.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"return-value-from-list-append\">Return Value from List append()<\/h2>\n\n\n\n<p>The <strong><code>append()<\/code><\/strong> method doesn\u2019t return any value.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>Note<\/strong>: A list is an object. If you append another list onto a list, the element list that gets added will be a single object at the end of the list.<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-1-adding-element-to-a-list\">Example 1: Adding Element to a List<\/h2>\n\n\n\n<p>ow to append element to a list in Python<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Programming list\nprogramming_list = &#91;'C','C#','Python','Java','JavaScript']\n\n# append the HTML item to the list\nprogramming_list.append('HTML')\nprint('The new list is :', programming_list)<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The new list is : &#91;'C', 'C#', 'Python', 'Java', 'JavaScript', 'HTML']<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-2-adding-list-into-the-list\">Example 2: Adding List into the List<\/h2>\n\n\n\n<p>Since we are appending a list into an existing list it would be added as a single element into the list as shown in below output.<\/p>\n\n\n\n<p>How to append a list into an existing list<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Programming list\nprogramming_list = &#91;'C','C#','Python','Java']\n\nfrontend_programming =&#91;'CSS','HTML','JavaScript']\n\n# append the frontend_progamming list into the existing list\nprogramming_list.append(frontend_programming)\n\n# Note that entire list is appended as a single element\nprint('The new appended list is :', programming_list)<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The new appended list is : &#91;'C', 'C#', 'Python', 'Java', &#91;'CSS', 'HTML', 'JavaScript']]<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The append() method in Python adds an element to the end of the list. After appending the new element, the size of the list increases by one. In this tutorial, we will learn about the Python list append() method with the help of examples. Syntax of List append()&nbsp; The syntax of the append() method is: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":521,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,1],"tags":[],"class_list":["post-520","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-list-methods","category-python"],"_links":{"self":[{"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/posts\/520","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/comments?post=520"}],"version-history":[{"count":1,"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/posts\/520\/revisions"}],"predecessor-version":[{"id":522,"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/posts\/520\/revisions\/522"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/media\/521"}],"wp:attachment":[{"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/media?parent=520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/categories?post=520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itsmycode.com\/wp-json\/wp\/v2\/tags?post=520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}