{"id":4772,"date":"2017-12-08T00:15:41","date_gmt":"2017-12-07T18:45:41","guid":{"rendered":"https:\/\/www.java2blog.com\/?p=4772"},"modified":"2021-10-25T00:26:34","modified_gmt":"2021-10-24T18:56:34","slug":"create-empty-list-python","status":"publish","type":"post","link":"https:\/\/java2blog.com\/create-empty-list-python\/","title":{"rendered":"How to create an empty list in python"},"content":{"rendered":"<p>In this post, we will see how to create an empty <a href=\"https:\/\/www.java2blog.com\/python-list-tutorial\/\" target=\"_blank\" rel=\"noopener\">list<\/a>  in python.<\/p>\n<p>There are two ways to create an empty list in Python.<\/p>\n<ul>\n<li>Using [ ]<\/li>\n<li>Using list() function.<\/li>\n<\/ul>\n<p>Let&#8217;s see this with the help of example.<\/p>\n<pre code=\"python\">\nlist1=[]\nlist1.append(1)\nlist1.append(2)\n\nlist2=list()\nlist2.append(1)\nlist2.append(2)\n\nprint(\"List 1:\",list1)\nprint(\"List 2:\",list2)\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<div class=\"content-box-green\">List 1: [1, 2]\nList 2: [1, 2]<\/div>\n<h2><span style=\"color: #f89820;\">Which is faster: [ ] or list()<\/span><\/h2>\n<p>list() is inherently slower than [], because of<\/p>\n<ul>\n<li>symbol lookup (no way for python to know in advance if you did not just redefine list to be something else!)<\/li>\n<li>function invocation<\/li>\n<li>then it has to check if there was iterable argument passed (so it can create list with elements from it)<\/li>\n<\/ul>\n<p>That&#8217;s all about creating empty list in python.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, we will see how to create an empty list in python. There are two ways to create an empty list in Python. Using [ ] Using list() function. Let&#8217;s see this with the help of example. list1=[] list1.append(1) list1.append(2) list2=list() list2.append(1) list2.append(2) print(&#8220;List 1:&#8221;,list1) print(&#8220;List 2:&#8221;,list2) Output: List 1: [1, 2] List [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"_mi_skip_tracking":false},"categories":[145,146],"tags":[],"_links":{"self":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts\/4772"}],"collection":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/comments?post=4772"}],"version-history":[{"count":0,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/posts\/4772\/revisions"}],"wp:attachment":[{"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/media?parent=4772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/categories?post=4772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/java2blog.com\/wp-json\/wp\/v2\/tags?post=4772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}