{"id":20627,"date":"2020-08-01T00:16:37","date_gmt":"2020-08-01T07:16:37","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=20627"},"modified":"2023-12-01T03:57:13","modified_gmt":"2023-12-01T11:57:13","slug":"python-nameerror-name-is-not-defined","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-is-not-defined\/","title":{"rendered":"Python nameerror name is not defined Solution"},"content":{"rendered":"\n<p>NameErrors are one of the most common types of Python errors. When you\u2019re first getting started, these errors can seem intimidating. They\u2019re not too complicated. A NameError means that you\u2019ve tried to use a variable that does not yet exist.<br><\/p>\n\n\n\n<p>In this guide, we\u2019re going to talk about the \u201cnameerror name is not defined\u201d error and why it is raised. We\u2019ll walk through a few example solutions to this error to help you understand how to resolve it in your code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is a NameError?<\/h2>\n\n\n\n<p>A NameError is raised when you try to use a <a href=\"https:\/\/careerkarma.com\/blog\/python-variables\/\">variable<\/a> or a <a href=\"https:\/\/careerkarma.com\/blog\/python-functions\/\">function<\/a> name that is not valid.<br><\/p>\n\n\n\n<p>In Python, code runs from top to bottom. This means that you cannot declare a variable after you try to use it in your code. Python would not know what you wanted the variable to do.<br><\/p>\n\n\n\n<p>The most common NameError looks like this:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>nameerror name is not defined<\/pre><\/div>\n\n\n\n<p>Let\u2019s analyze a few causes of this error.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cause #1: Misspelled Variable or Function Name<\/h2>\n\n\n\n<p>It\u2019s easy for humans to gloss over spelling mistakes. We can easily tell what a word is supposed to be even if it is misspelled. Python does not have this capability.<br><\/p>\n\n\n\n<p>Python can only interpret names that you have spelled correctly. This is because when you declare a variable or a function, Python stores the value with the exact name you have declared.<br><\/p>\n\n\n\n<p>If there is a typo anywhere that you try to reference that variable, an error will be returned.<br><\/p>\n\n\n\n<p>Consider the following code snippet:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>books = [&quot;Near Dark&quot;, &quot;The Order&quot;, &quot;Where the Crawdads Sing&quot;]\n\nprint(boooks)<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/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 3, in &lt;module&gt;\n\tprint(boooks)\nNameError: name 'boooks' is not defined<\/pre><\/div>\n\n\n\n<p>To solve this problem, all we have to do is fix the typo. If we use \u201cprint(books)\u201d, our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[&quot;Near Dark&quot;, &quot;The Order&quot;, &quot;Where the Crawdads Sing&quot;]<\/pre><\/div>\n\n\n\n<p>If you receive a name error, you should first check to make sure that you have spelled the variable or function name correctly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cause #2: Calling a Function Before Declaration<\/h2>\n\n\n\n<p>Functions must be declared before they are used, like variables. This is because Python reads code from top-to-bottom.&nbsp;<br><\/p>\n\n\n\n<p>Let\u2019s write a program that calls a function before it is declared:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>books = [&quot;Near Dark&quot;, &quot;The Order&quot;, &quot;Where the Crawdads Sing&quot;]\n\nprint_books(books)\n\ndef print_books(books):\n\tfor b in books:\n\t\tprint(b)<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/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 3, in &lt;module&gt;\n\tprint_books(books)\nNameError: name 'print_books' is not defined<\/pre><\/div>\n\n\n\n<p>We are trying to call print_books() on line three. However, we do not define this function until later in our program. To fix this error, we can move our function declaration to a place before we use it:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>def print_books(books):\n\tfor b in books:\n\t\tprint(b)\n\nbooks = [&quot;Near Dark&quot;, &quot;The Order&quot;, &quot;Where the Crawdads Sing&quot;]\n\nprint_books(books)<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Near Dark\nThe Order\nWhere the Crawdads Sing<\/pre><\/div>\n\n\n\n<p>Our code has successfully printed out the list of books.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cause #3: Forget to Define a Variable<\/h2>\n\n\n\n<p>As programs get larger, it is easy to forget to define a variable. If you do, a name error is raised. This is because Python cannot work with variables until they are declared.<br><\/p>\n\n\n\n<p>Let\u2019s take a look at a program that prints out a <a href=\"https:\/\/careerkarma.com\/blog\/python-array\/\">list<\/a> of books:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>for b in books:\nprint(b)<\/pre><\/div>\n\n\n\n<p>Our code returns:&nbsp;<\/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 1, in &lt;module&gt;\n\tfor b in books:\nNameError: name 'books' is not defined<\/pre><\/div>\n\n\n\n<p>We have not declared a variable called \u201cbooks\u201d. To solve this problem, we need to declare \u201cbooks\u201d before we use it in our code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>books = [&quot;Near Dark&quot;, &quot;The Order&quot;, &quot;Where the Crawdads Sing&quot;]\n\nfor b in books:\nprint(b)<\/pre><\/div>\n\n\n\n<p>Let\u2019s try to run our program again and see what happens:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Near Dark\nThe Order\nWhere the Crawdads Sing<\/pre><\/div>\n\n\n\n<p>Now that we have defined a list of books, Python can print out each book from the list.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cause #4: Try to Print a Single Word<\/h2>\n\n\n\n<p>To print out a word in Python, you need to surround it in either single or double quotes. This tells Python that a word is a string. If a word is not surrounded by quotes, it is treated as part of a program. Consider the following <a href=\"https:\/\/careerkarma.com\/blog\/python-print-without-new-line\/\">print() statement<\/a>:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>print(Books)<\/pre><\/div>\n\n\n\n<p>This code tries to print the word \u201cBooks\u201d to the console. The code returns an error:<\/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 1, in &lt;module&gt;\n\tprint(Books)\nNameError: name 'Books' is not defined<\/pre><\/div>\n\n\n\n<p>Python treats \u201cBooks\u201d like a variable name. To solve this error, we can enclose the word \u201cBooks\u201d in quotation marks:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>print(&quot;Books&quot;)<\/pre><\/div>\n\n\n\n<p>Python now knows that we want to print out a string to the console. Our new code returns: Books.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Cause #5: Declaring a Variable Out of Scope<\/h2>\n\n\n\n<p>There are two variable scopes: <a href=\"https:\/\/careerkarma.com\/blog\/python-global-local-variables\/\">local and global<\/a>.<br><\/p>\n\n\n\n<p>Local variables are only accessible in the function or class in which they are declared. Global variables are accessible throughout a program.<br><\/p>\n\n\n\n<p>If you try to access a local variable outside the scope in which it is defined, an error is raised.<br><\/p>\n\n\n\n<p>The following code should print out a list of books followed by the number of books in the list:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>def print_books():\n  books = [&quot;Near Dark&quot;, &quot;The Order&quot;, &quot;Where the Crawdads Sing&quot;]\n  for b in books:\n      print(b)\n\nprint_books()\nprint(len(books))<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Near Dark\nThe Order\nWhere the Crawdads Sing\nTraceback (most recent call last):\n  File &quot;main.py&quot;, line 6, in &lt;module&gt;\n\tprint(len(books))\nNameError: name 'books' is not defined<\/pre><\/div>\n\n\n\n<p>Our code successfully prints out the list of books. On the last line of our code, an error is returned. While we have declared the variable \u201cbooks\u201d, we only declared it inside our print_books() function. This means the variable is not accessible to the rest of our program.<br><\/p>\n\n\n\n<p>To solve this problem, we can declare books in our main program. This will make it a global variable:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>books = [&quot;Near Dark&quot;, &quot;The Order&quot;, &quot;Where the Crawdads Sing&quot;]\n\ndef print_books():\n  for b in books:\n      print(b)\n\nprint_books()\nprint(len(books))<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Near Dark\nThe Order\nWhere the Crawdads Sing\n3<\/pre><\/div>\n\n\n\n<p>Our code prints out every book in the &#8220;books&#8221; list. Then, our code prints out the number of books in the list using the len() method.<\/p>\n\n\n\n<iframe loading=\"lazy\" src=\"https:\/\/repl.it\/@careerkarma\/nameerror-name-is-not-defined?lite=true\" width=\"100%\" height=\"400px\" frameborder=\"0\"><\/iframe>\n<br>\n<br>\n","protected":false},"excerpt":{"rendered":"NameErrors are one of the most common types of Python errors. When you\u2019re first getting started, these errors can seem intimidating. They\u2019re not too complicated. A NameError means that you\u2019ve tried to use a variable that does not yet exist. In this guide, we\u2019re going to talk about the \u201cnameerror name is not defined\u201d error&hellip;","protected":false},"author":240,"featured_media":20628,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-20627","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.6 (Yoast SEO v27.6) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python nameerror name is not defined Solution | Career Karma<\/title>\n<meta name=\"description\" content=\"On Career Karma, learn about the Python nameerror name is not defined error, why it is raised, and how to solve it.\" \/>\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-nameerror-name-is-not-defined\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python nameerror name is not defined Solution\" \/>\n<meta property=\"og:description\" content=\"On Career Karma, learn about the Python nameerror name is not defined error, why it is raised, and how to solve it.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/python-nameerror-name-is-not-defined\/\" \/>\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-01T07:16:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:57:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/gustas-brazaitis-xNKy-Cu20d4-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\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-nameerror-name-is-not-defined\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-is-not-defined\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Python nameerror name is not defined Solution\",\"datePublished\":\"2020-08-01T07:16:37+00:00\",\"dateModified\":\"2023-12-01T11:57:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-is-not-defined\\\/\"},\"wordCount\":799,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-is-not-defined\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/gustas-brazaitis-xNKy-Cu20d4-unsplash.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-is-not-defined\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-is-not-defined\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-is-not-defined\\\/\",\"name\":\"Python nameerror name is not defined Solution | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-is-not-defined\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-is-not-defined\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/gustas-brazaitis-xNKy-Cu20d4-unsplash.jpg\",\"datePublished\":\"2020-08-01T07:16:37+00:00\",\"dateModified\":\"2023-12-01T11:57:13+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"On Career Karma, learn about the Python nameerror name is not defined error, why it is raised, and how to solve it.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-is-not-defined\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-is-not-defined\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-is-not-defined\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/gustas-brazaitis-xNKy-Cu20d4-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/gustas-brazaitis-xNKy-Cu20d4-unsplash.jpg\",\"width\":1020,\"height\":680},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-is-not-defined\\\/#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 nameerror name is not defined 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\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"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 nameerror name is not defined Solution | Career Karma","description":"On Career Karma, learn about the Python nameerror name is not defined error, why it is raised, and how to solve it.","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-nameerror-name-is-not-defined\/","og_locale":"en_US","og_type":"article","og_title":"Python nameerror name is not defined Solution","og_description":"On Career Karma, learn about the Python nameerror name is not defined error, why it is raised, and how to solve it.","og_url":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-is-not-defined\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-08-01T07:16:37+00:00","article_modified_time":"2023-12-01T11:57:13+00:00","og_image":[{"width":1020,"height":680,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/gustas-brazaitis-xNKy-Cu20d4-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-nameerror-name-is-not-defined\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-is-not-defined\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Python nameerror name is not defined Solution","datePublished":"2020-08-01T07:16:37+00:00","dateModified":"2023-12-01T11:57:13+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-is-not-defined\/"},"wordCount":799,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-is-not-defined\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/gustas-brazaitis-xNKy-Cu20d4-unsplash.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/python-nameerror-name-is-not-defined\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-is-not-defined\/","url":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-is-not-defined\/","name":"Python nameerror name is not defined Solution | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-is-not-defined\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-is-not-defined\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/gustas-brazaitis-xNKy-Cu20d4-unsplash.jpg","datePublished":"2020-08-01T07:16:37+00:00","dateModified":"2023-12-01T11:57:13+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"On Career Karma, learn about the Python nameerror name is not defined error, why it is raised, and how to solve it.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-is-not-defined\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/python-nameerror-name-is-not-defined\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-is-not-defined\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/gustas-brazaitis-xNKy-Cu20d4-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/gustas-brazaitis-xNKy-Cu20d4-unsplash.jpg","width":1020,"height":680},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-is-not-defined\/#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 nameerror name is not defined 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\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","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\/20627","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=20627"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/20627\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/20628"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=20627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=20627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=20627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}