{"id":2518,"date":"2017-07-21T13:00:47","date_gmt":"2017-07-21T13:00:47","guid":{"rendered":"http:\/\/98.80.187.15\/?p=2518"},"modified":"2024-07-23T22:43:17","modified_gmt":"2024-07-24T02:43:17","slug":"comparing-blank-string-definition-in-python3","status":"publish","type":"post","link":"https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/","title":{"rendered":"Comparing blank string definition in Python3"},"content":{"rendered":"<p>In python3 using<\/p>\n<pre class=\"lang:python decode:true\">string = \"\"\r\n<\/pre>\n<p>or<\/p>\n<pre class=\"lang:python decode:true\">string = str()\r\n<\/pre>\n<p>Produces the same result for the programmer. Which one is faster? Using the python module <a href=\"https:\/\/docs.python.org\/3\/library\/timeit.html\">timeit<\/a>, it&#8217;s really easy to find out!<\/p>\n<p><a href=\"https:\/\/www.esologic.com\/wp-content\/uploads\/2017\/07\/graph-2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2524\" src=\"https:\/\/www.esologic.com\/wp-content\/uploads\/2017\/07\/graph-2.png\" alt=\"\" width=\"5833\" height=\"3960\" srcset=\"https:\/\/esologic.com\/wp-content\/uploads\/2017\/07\/graph-2.png 5833w, https:\/\/esologic.com\/wp-content\/uploads\/2017\/07\/graph-2-600x407.png 600w, https:\/\/esologic.com\/wp-content\/uploads\/2017\/07\/graph-2-300x204.png 300w, https:\/\/esologic.com\/wp-content\/uploads\/2017\/07\/graph-2-768x521.png 768w, https:\/\/esologic.com\/wp-content\/uploads\/2017\/07\/graph-2-644x437.png 644w\" sizes=\"auto, (max-width: 5833px) 100vw, 5833px\" \/><\/a><\/p>\n<p>Using <code>string=\"\"<\/code> is WAY faster.<\/p>\n<p>Here&#8217;s the source code for my tests:<\/p>\n<pre class=\"lang:python decode:true\">from timeit import timeit\r\n\r\ndurations = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000]\r\ndefinition_techniques = ['s=\"\"', 's=str()']\r\n\r\nfor definition_technique in definition_techniques:\r\n    print(definition_technique + ' durations')\r\n    for duration in durations:\r\n        print(timeit(definition_technique, number=duration))\r\n<\/pre>\n<p><script src=\"https:\/\/www.moovmanage.com\/public_api\/moovad_overlay\/24889\" type=\"text\/javascript\"><\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In python3 using string = &#8220;&#8221; or string = str() Produces the same result for the programmer. Which one is faster? Using the python module timeit, it&#8217;s really easy to find out! Using string=&#8221;&#8221; is WAY faster. Here&#8217;s the source code for my tests: from timeit import timeit durations = [1, 10, 100, 1000, 10000,&#8230;<\/p>\n","protected":false},"author":1,"featured_media":2523,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[162],"tags":[177],"class_list":["post-2518","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-demo","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Comparing blank string definition in Python3 - esologic<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Comparing blank string definition in Python3 - esologic\" \/>\n<meta property=\"og:description\" content=\"In python3 using string = &quot;&quot; or string = str() Produces the same result for the programmer. Which one is faster? Using the python module timeit, it&#8217;s really easy to find out! Using string=&quot;&quot; is WAY faster. Here&#8217;s the source code for my tests: from timeit import timeit durations = [1, 10, 100, 1000, 10000,...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/\" \/>\n<meta property=\"og:site_name\" content=\"esologic\" \/>\n<meta property=\"article:published_time\" content=\"2017-07-21T13:00:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-07-24T02:43:17+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/esologic.com\/wp-content\/uploads\/2017\/07\/graph-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"4167\" \/>\n\t<meta property=\"og:image:height\" content=\"2829\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Devon\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Devon\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/esologic.com\\\/comparing-blank-string-definition-in-python3\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/esologic.com\\\/comparing-blank-string-definition-in-python3\\\/\"},\"author\":{\"name\":\"Devon\",\"@id\":\"https:\\\/\\\/esologic.com\\\/#\\\/schema\\\/person\\\/25fe9b9fbfd4f40d9de0eb261a8ae84d\"},\"headline\":\"Comparing blank string definition in Python3\",\"datePublished\":\"2017-07-21T13:00:47+00:00\",\"dateModified\":\"2024-07-24T02:43:17+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/esologic.com\\\/comparing-blank-string-definition-in-python3\\\/\"},\"wordCount\":45,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/esologic.com\\\/comparing-blank-string-definition-in-python3\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/esologic.com\\\/wp-content\\\/uploads\\\/2017\\\/07\\\/graph-1.png\",\"keywords\":[\"python\"],\"articleSection\":[\"Demo\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/esologic.com\\\/comparing-blank-string-definition-in-python3\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/esologic.com\\\/comparing-blank-string-definition-in-python3\\\/\",\"url\":\"https:\\\/\\\/esologic.com\\\/comparing-blank-string-definition-in-python3\\\/\",\"name\":\"Comparing blank string definition in Python3 - esologic\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/esologic.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/esologic.com\\\/comparing-blank-string-definition-in-python3\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/esologic.com\\\/comparing-blank-string-definition-in-python3\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/esologic.com\\\/wp-content\\\/uploads\\\/2017\\\/07\\\/graph-1.png\",\"datePublished\":\"2017-07-21T13:00:47+00:00\",\"dateModified\":\"2024-07-24T02:43:17+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/esologic.com\\\/#\\\/schema\\\/person\\\/25fe9b9fbfd4f40d9de0eb261a8ae84d\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/esologic.com\\\/comparing-blank-string-definition-in-python3\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/esologic.com\\\/comparing-blank-string-definition-in-python3\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/esologic.com\\\/comparing-blank-string-definition-in-python3\\\/#primaryimage\",\"url\":\"https:\\\/\\\/esologic.com\\\/wp-content\\\/uploads\\\/2017\\\/07\\\/graph-1.png\",\"contentUrl\":\"https:\\\/\\\/esologic.com\\\/wp-content\\\/uploads\\\/2017\\\/07\\\/graph-1.png\",\"width\":4167,\"height\":2829},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/esologic.com\\\/comparing-blank-string-definition-in-python3\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/esologic.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Comparing blank string definition in Python3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/esologic.com\\\/#website\",\"url\":\"https:\\\/\\\/esologic.com\\\/\",\"name\":\"esologic\",\"description\":\"Devon Bray&#039;s Project Portfolio &amp; Development Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/esologic.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/esologic.com\\\/#\\\/schema\\\/person\\\/25fe9b9fbfd4f40d9de0eb261a8ae84d\",\"name\":\"Devon\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3c0b44a1be0009def7725519abcf6e05c45f3d6b91e1b088de12d97ccd4ae3b6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3c0b44a1be0009def7725519abcf6e05c45f3d6b91e1b088de12d97ccd4ae3b6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/3c0b44a1be0009def7725519abcf6e05c45f3d6b91e1b088de12d97ccd4ae3b6?s=96&d=mm&r=g\",\"caption\":\"Devon\"},\"sameAs\":[\"https:\\\/\\\/esologic.com\"],\"url\":\"https:\\\/\\\/esologic.com\\\/author\\\/devon\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Comparing blank string definition in Python3 - esologic","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/","og_locale":"en_US","og_type":"article","og_title":"Comparing blank string definition in Python3 - esologic","og_description":"In python3 using string = \"\" or string = str() Produces the same result for the programmer. Which one is faster? Using the python module timeit, it&#8217;s really easy to find out! Using string=\"\" is WAY faster. Here&#8217;s the source code for my tests: from timeit import timeit durations = [1, 10, 100, 1000, 10000,...","og_url":"https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/","og_site_name":"esologic","article_published_time":"2017-07-21T13:00:47+00:00","article_modified_time":"2024-07-24T02:43:17+00:00","og_image":[{"width":4167,"height":2829,"url":"https:\/\/esologic.com\/wp-content\/uploads\/2017\/07\/graph-1.png","type":"image\/png"}],"author":"Devon","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Devon","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/#article","isPartOf":{"@id":"https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/"},"author":{"name":"Devon","@id":"https:\/\/esologic.com\/#\/schema\/person\/25fe9b9fbfd4f40d9de0eb261a8ae84d"},"headline":"Comparing blank string definition in Python3","datePublished":"2017-07-21T13:00:47+00:00","dateModified":"2024-07-24T02:43:17+00:00","mainEntityOfPage":{"@id":"https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/"},"wordCount":45,"commentCount":0,"image":{"@id":"https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/#primaryimage"},"thumbnailUrl":"https:\/\/esologic.com\/wp-content\/uploads\/2017\/07\/graph-1.png","keywords":["python"],"articleSection":["Demo"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/","url":"https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/","name":"Comparing blank string definition in Python3 - esologic","isPartOf":{"@id":"https:\/\/esologic.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/#primaryimage"},"image":{"@id":"https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/#primaryimage"},"thumbnailUrl":"https:\/\/esologic.com\/wp-content\/uploads\/2017\/07\/graph-1.png","datePublished":"2017-07-21T13:00:47+00:00","dateModified":"2024-07-24T02:43:17+00:00","author":{"@id":"https:\/\/esologic.com\/#\/schema\/person\/25fe9b9fbfd4f40d9de0eb261a8ae84d"},"breadcrumb":{"@id":"https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/#primaryimage","url":"https:\/\/esologic.com\/wp-content\/uploads\/2017\/07\/graph-1.png","contentUrl":"https:\/\/esologic.com\/wp-content\/uploads\/2017\/07\/graph-1.png","width":4167,"height":2829},{"@type":"BreadcrumbList","@id":"https:\/\/esologic.com\/comparing-blank-string-definition-in-python3\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/esologic.com\/"},{"@type":"ListItem","position":2,"name":"Comparing blank string definition in Python3"}]},{"@type":"WebSite","@id":"https:\/\/esologic.com\/#website","url":"https:\/\/esologic.com\/","name":"esologic","description":"Devon Bray&#039;s Project Portfolio &amp; Development Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/esologic.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/esologic.com\/#\/schema\/person\/25fe9b9fbfd4f40d9de0eb261a8ae84d","name":"Devon","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/3c0b44a1be0009def7725519abcf6e05c45f3d6b91e1b088de12d97ccd4ae3b6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/3c0b44a1be0009def7725519abcf6e05c45f3d6b91e1b088de12d97ccd4ae3b6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/3c0b44a1be0009def7725519abcf6e05c45f3d6b91e1b088de12d97ccd4ae3b6?s=96&d=mm&r=g","caption":"Devon"},"sameAs":["https:\/\/esologic.com"],"url":"https:\/\/esologic.com\/author\/devon\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/esologic.com\/wp-content\/uploads\/2017\/07\/graph-1.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/esologic.com\/wp-json\/wp\/v2\/posts\/2518","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/esologic.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/esologic.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/esologic.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/esologic.com\/wp-json\/wp\/v2\/comments?post=2518"}],"version-history":[{"count":6,"href":"https:\/\/esologic.com\/wp-json\/wp\/v2\/posts\/2518\/revisions"}],"predecessor-version":[{"id":2527,"href":"https:\/\/esologic.com\/wp-json\/wp\/v2\/posts\/2518\/revisions\/2527"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/esologic.com\/wp-json\/wp\/v2\/media\/2523"}],"wp:attachment":[{"href":"https:\/\/esologic.com\/wp-json\/wp\/v2\/media?parent=2518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/esologic.com\/wp-json\/wp\/v2\/categories?post=2518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/esologic.com\/wp-json\/wp\/v2\/tags?post=2518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}