{"id":21604,"date":"2020-08-25T14:13:19","date_gmt":"2020-08-25T21:13:19","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=21604"},"modified":"2023-12-01T03:58:48","modified_gmt":"2023-12-01T11:58:48","slug":"python-typeerror-object-of-type-nonetype-has-no-len","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/","title":{"rendered":"Python TypeError: object of type \u2018NoneType\u2019 has no len() Solution"},"content":{"rendered":"\n<p>The <code>len()<\/code> method only works on iterable objects such as strings, lists, and dictionaries. This is because iterable objects contain sequences of values. If you try to use the <code>len()<\/code> method on a None value, you\u2019ll encounter the error \u201cTypeError: object of type \u2018NoneType\u2019 has no <code>len()<\/code>\u201d.<br><\/p>\n\n\n\n<p>In this guide, we talk about what this error means and how it works. We walk through two examples of this error in action so you can figure out how to solve it in your code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">TypeError: object of type \u2018NoneType\u2019 has no len()<\/h2>\n\n\n\n<p>NoneType refers to the None data type. You cannot use methods that would work on iterable objects, such as <code>len()<\/code>, on a None value. This is because None does not contain a collection of values. The length of None cannot be calculated because None has no child values.<br><\/p>\n\n\n\n<p>This error is common in two cases:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Where you forget that built-in functions change a list in-place<\/li><li>Where you forget a return statement in a function<\/li><\/ul>\n\n\n\n<p>Let\u2019s take a look at each of these causes in depth.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cause #1: Built-In Functions Change Lists In-Place<\/h2>\n\n\n\n<p>We\u2019re going to build a program that sorts a list of dictionaries containing information about students at a school. We\u2019ll sort this list in ascending order of a student&#8217;s grade on their last test.<br><\/p>\n\n\n\n<p>To start, define a list of dictionaries that contains information about students and their most recent test score:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>students = [\n\t{&quot;name&quot;: &quot;Peter&quot;, &quot;score&quot;: 76 },\n\t{&quot;name&quot;: &quot;Richard&quot;, &quot;score&quot;: 63 },\n{&quot;name&quot;: &quot;Erin&quot;, &quot;score&quot;: 64 },\n{&quot;name&quot;: &quot;Miley&quot;, &quot;score&quot;: 89 }\n]<\/pre><\/div>\n\n\n\n<p>Each dictionary contains two keys and values. One corresponds with the name of a student and the other corresponds with the score a student earned on their last test. Next, use the <code>sort()<\/code> method to sort our list of students:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>def score_sort(s):\n\treturn s[&quot;score&quot;]\n\n\n\nsorted_students = students.sort(key=score_sort)<\/pre><\/div>\n\n\n\n<p>We have declared a function called \u201cscore_sort\u201d which returns the value of \u201cscore\u201d in each dictionary. We then use this to order the items in our list of dictionaries using the <code>sort()<\/code> method.<br><\/p>\n\n\n\n<p>Next, we print out the length of our list:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>print(&quot;There are {} students in the list.&quot;.format(len(sorted_students)))<\/pre><\/div>\n\n\n\n<p>We print out the new list of dictionaries to the console using a for loop: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>for s in sorted_students:\n\tprint(&quot;{} earned a score of {} on their last test.&quot;.format(s[&quot;name&quot;], s[&quot;score&quot;]))<\/pre><\/div>\n\n\n\n<p>This code prints out a message informing us of how many marks a student earned on their last test for each student in the \u201csorted_students\u201d list. Let\u2019s run our code:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Traceback (most recent call last):\n  File &quot;main.py&quot;, line 13, in &lt;module&gt;\n\tprint(&quot;There are {} students in the list.&quot;.format(len(sorted_students)))\nTypeError: object of type 'NoneType' has no len()<\/pre><\/div>\n\n\n\n<p>Our code returns an error.<br><\/p>\n\n\n\n<p>To solve this problem, we need to remove the code where we assign the result of the <code>sort()<\/code> method to \u201csorted_students\u201d. This is because the <code>sort()<\/code> method changes a list in place. It does not create a new list.<br><\/p>\n\n\n\n<p>Remove the declaration of the \u201csorted_students\u201d list and use \u201cstudents\u201d in the rest of our program:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>students.sort(key=score_sort)\n\nprint(&quot;There are {} students in the list.&quot;.format(len(students)))\n\nfor s in students:\n\tprint(&quot;{} earned a score of {} on their last test.&quot;.format(s[&quot;name&quot;], s[&quot;score&quot;]))<\/pre><\/div>\n\n\n\n<p>Run our code and see what happens:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>There are 4 students in the list.\nRichard earned a score of 63 on their last test.\nErin earned a score of 64 on their last test.\nPeter earned a score of 76 on their last test.\nMiley earned a score of 89 on their last test.<\/pre><\/div>\n\n\n\n<p>Our code executes successfully. First, our code tells us how many students are in our list. Our code then prints out information about each student and how many marks they earned on their last test. This information is printed out in ascending order of a student\u2019s grade.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cause #2: Forgetting a Return Statement<\/h2>\n\n\n\n<p>We\u2019re going to make our code more modular. To do this, we move our sorting method into its own function. We\u2019ll also define a function that prints out information about what score each student earned on their test.<br><\/p>\n\n\n\n<p>Start by defining our list of students and our sorting helper function. We\u2019ll borrow this code from earlier in the tutorial.<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>students = [\n\t{&quot;name&quot;: &quot;Peter&quot;, &quot;score&quot;: 76 },\n\t{&quot;name&quot;: &quot;Richard&quot;, &quot;score&quot;: 63 },\n{&quot;name&quot;: &quot;Erin&quot;, &quot;score&quot;: 64 },\n{&quot;name&quot;: &quot;Miley&quot;, &quot;score&quot;: 89 }\n]\n\ndef score_sort(s):\n\treturn s[&quot;score&quot;]<\/pre><\/div>\n\n\n\n<p>Next, write a function that sorts our list:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>def sort_list(students):\n\tstudents.sort(key=score_sort)<\/pre><\/div>\n\n\n\n<p>Finally, we define a function that displays information about each students\u2019 performance:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>def show_students(new_students):\n\tprint(&quot;There are {} students in the list.&quot;.format(len(students)))\n\tfor s in new_students:\n\t\t\t print(&quot;{} earned a score of {} on their last test.&quot;.format(s[&quot;name&quot;], s[&quot;score&quot;]))<\/pre><\/div>\n\n\n\n<p>Before we run our code, we have to call our functions:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>new_students = sort_list(students)\nshow_students(new_students)<\/pre><\/div>\n\n\n\n<p>Our program will first sort our list using the <code>sort_list()<\/code> function. Then, our program will print out information about each student to the console. This is handled in the <code>show_students()<\/code> function.<\/p>\n\n\n\n<p>Let\u2019s run our code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Traceback (most recent call last):\n  File &quot;main.py&quot;, line 21, in &lt;module&gt;\n\tshow_students(new_students)\n  File &quot;main.py&quot;, line 15, in show_students\n\tprint(&quot;There are {} students in the list.&quot;.format(len(new_students)))\nTypeError: object of type 'NoneType' has no len()<\/pre><\/div>\n\n\n\n<p>Our code returns an error. This error has occured because we have forgotten to include a \u201creturn\u201d statement in our \u201csort_list\u201d function.<br><\/p>\n\n\n\n<p>When we call our <code>sort_list()<\/code> function, we assign its response to the variable \u201cnew_students\u201d. That variable is passed into our <code>show_students()<\/code> function that displays information about each student. To solve this error, we must add a return statement to the <code>sort_list()<\/code> function:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>def sort_list(students):\n\tstudents.sort(key=score_sort)\n\treturn students<\/pre><\/div>\n\n\n\n<p>Run our code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>There are 4 students in the list.\nRichard earned a score of 63 on their last test.\nErin earned a score of 64 on their last test.\nPeter earned a score of 76 on their last test.\nMiley earned a score of 89 on their last test.<\/pre><\/div>\n\n\n\n<p>Our code returns the response we expected.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The \u201cTypeError: object of type \u2018NoneType\u2019 has no <code>len()<\/code>\u201d error is caused when you try to use the <code>len()<\/code> method on an object whose value is None.<br><\/p>\n\n\n\n<p>To solve this error, make sure that you are not assigning the responses of any built-in list methods, like <code>sort()<\/code>, to a variable. If this does not solve the error, make sure your program has all the \u201creturn\u201d statements it needs to function successfully.<br><\/p>\n\n\n\n<p>Now you\u2019re ready to solve this problem like a Python professional!<\/p>\n","protected":false},"excerpt":{"rendered":"The len() method only works on iterable objects such as strings, lists, and dictionaries. This is because iterable objects contain sequences of values. If you try to use the len() method on a None value, you\u2019ll encounter the error \u201cTypeError: object of type \u2018NoneType\u2019 has no len()\u201d. In this guide, we talk about what this&hellip;","protected":false},"author":240,"featured_media":21605,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-21604","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-python"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Python","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":[]},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python TypeError: object of type \u2018NoneType\u2019 has no len() | Career Karma<\/title>\n<meta name=\"description\" content=\"The Python TypeError: object of type \u2018NoneType\u2019 has no len() is raised when you calculate the length of a None object. On Career Karma, learn how to fix this error.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python TypeError: object of type \u2018NoneType\u2019 has no len() Solution\" \/>\n<meta property=\"og:description\" content=\"The Python TypeError: object of type \u2018NoneType\u2019 has no len() is raised when you calculate the length of a None object. On Career Karma, learn how to fix this error.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-25T21:13:19+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:58:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/lewis-ngugi-f5pTwLHCsAg-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"736\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Python TypeError: object of type \u2018NoneType\u2019 has no len() Solution\",\"datePublished\":\"2020-08-25T21:13:19+00:00\",\"dateModified\":\"2023-12-01T11:58:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/\"},\"wordCount\":774,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/lewis-ngugi-f5pTwLHCsAg-unsplash.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/\",\"name\":\"Python TypeError: object of type \u2018NoneType\u2019 has no len() | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/lewis-ngugi-f5pTwLHCsAg-unsplash.jpg\",\"datePublished\":\"2020-08-25T21:13:19+00:00\",\"dateModified\":\"2023-12-01T11:58:48+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"The Python TypeError: object of type \u2018NoneType\u2019 has no len() is raised when you calculate the length of a None object. On Career Karma, learn how to fix this error.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/lewis-ngugi-f5pTwLHCsAg-unsplash.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/lewis-ngugi-f5pTwLHCsAg-unsplash.jpg\",\"width\":1020,\"height\":736,\"caption\":\"black laptop computer turned on\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\/\/careerkarma.com\/blog\/python\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python TypeError: object of type \u2018NoneType\u2019 has no len() Solution\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python TypeError: object of type \u2018NoneType\u2019 has no len() | Career Karma","description":"The Python TypeError: object of type \u2018NoneType\u2019 has no len() is raised when you calculate the length of a None object. On Career Karma, learn how to fix this error.","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:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/","og_locale":"en_US","og_type":"article","og_title":"Python TypeError: object of type \u2018NoneType\u2019 has no len() Solution","og_description":"The Python TypeError: object of type \u2018NoneType\u2019 has no len() is raised when you calculate the length of a None object. On Career Karma, learn how to fix this error.","og_url":"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-08-25T21:13:19+00:00","article_modified_time":"2023-12-01T11:58:48+00:00","og_image":[{"width":1020,"height":736,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/lewis-ngugi-f5pTwLHCsAg-unsplash.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Python TypeError: object of type \u2018NoneType\u2019 has no len() Solution","datePublished":"2020-08-25T21:13:19+00:00","dateModified":"2023-12-01T11:58:48+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/"},"wordCount":774,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/lewis-ngugi-f5pTwLHCsAg-unsplash.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/","url":"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/","name":"Python TypeError: object of type \u2018NoneType\u2019 has no len() | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/lewis-ngugi-f5pTwLHCsAg-unsplash.jpg","datePublished":"2020-08-25T21:13:19+00:00","dateModified":"2023-12-01T11:58:48+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"The Python TypeError: object of type \u2018NoneType\u2019 has no len() is raised when you calculate the length of a None object. On Career Karma, learn how to fix this error.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/lewis-ngugi-f5pTwLHCsAg-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/lewis-ngugi-f5pTwLHCsAg-unsplash.jpg","width":1020,"height":736,"caption":"black laptop computer turned on"},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/python-typeerror-object-of-type-nonetype-has-no-len\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/careerkarma.com\/blog\/python\/"},{"@type":"ListItem","position":3,"name":"Python TypeError: object of type \u2018NoneType\u2019 has no len() Solution"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/21604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=21604"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/21604\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/21605"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=21604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=21604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=21604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}