{"id":21288,"date":"2020-08-17T12:22:11","date_gmt":"2020-08-17T19:22:11","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=21288"},"modified":"2023-12-01T03:57:59","modified_gmt":"2023-12-01T11:57:59","slug":"python-nameerror-name-self-is-not-defined","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-self-is-not-defined\/","title":{"rendered":"Python NameError: name \u2018self\u2019 is not defined Solution"},"content":{"rendered":"\n<p>The value \u201cself\u201d is only available inside a method when a <a href=\"https:\/\/careerkarma.com\/blog\/python-functions\/\">function<\/a> is called and specified.<br><\/p>\n\n\n\n<p>You cannot access \u201cself\u201d in the arguments specified to a method, or inside a function without specifying \u201cself\u201d as an argument. Otherwise, you see the error \u201cNameError: name \u2018self\u2019 is not defined\u201d.<br><\/p>\n\n\n\n<p>In this guide, we talk about what this error means and why it is raised. We walk through a few code snippets to help you figure out how to solve this error in your code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">NameError: name &#8216;self&#8217; is not defined<\/h2>\n\n\n\n<p>The \u201cself\u201d variable holds information about an object inside a <a href=\"https:\/\/careerkarma.com\/blog\/python-class\/\">class<\/a>. All of the values that have been assigned to an object are available in the \u201cself\u201d variable.<br><\/p>\n\n\n\n<p>\u201cself\u201d must be passed as an <a href=\"https:\/\/careerkarma.com\/blog\/python-args-kwargs\/\">argument<\/a> if you want to use it in a method. The \u201cself\u201d variable cannot be used in other arguments in a method because it is only accessible from within a method.<br><\/p>\n\n\n\n<p>You encounter the \u201cNameError: name \u2018self\u2019 is not defined\u201d error if you:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Do not specify \u201cself\u201d as an argument<\/li><li>Use \u201cself\u201d as an argument in another argument<\/li><\/ul>\n\n\n\n<p>Let\u2019s walk through each of these scenarios one-by-one.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Scenario #1: \u201cself\u201d is Not Listed as an Argument<\/h2>\n\n\n\n<p>\u201cself\u201d must be listed as an argument for it to be accessible in a method. \u201cself\u201d is not a global variable. It is local inside a class.<br><\/p>\n\n\n\n<p>Write a program that holds information about movies in a class. We start by defining our class with a constructor that holds values about our movie:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>class Movie:\n\tdef __init__(self, name, year_released):\n\t\t\tself.name = name\n\t\t\tself.year_released = year_released<\/pre><\/div>\n\n\n\n<p>Our class can hold two values: the name of a movie and the year in which it was released. Next, we declare a method that lets us change the value of \u201cyear_released\u201d:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>\tdef change_year(year_released):\n\t\t   self.year_released = year_released\n\t\t   print(&quot;{} was released in {}.&quot;.format(self.name, self.year_released))<\/pre><\/div>\n\n\n\n<p>To test our code, we create an object of our class. This object represents the movie Happy Gilmore, released in 1996:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>happy_gilmore = Movie(&quot;Happy Gilmore&quot;)\nhappy_gilmore.change_year(1996)<\/pre><\/div>\n\n\n\n<p>We have called the <code>change_year()<\/code> method on our <a href=\"https:\/\/careerkarma.com\/blog\/python-class\/\">object<\/a> so that we can set the year the movie was released to 1996. Let\u2019s run our code and see if it works:<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 11, in &lt;module&gt;\n\thappy_gilmore.change_year()\n  File &quot;main.py&quot;, line 7, in change_year\n\tself.year_released = year_released\nNameError: name 'self' is not defined<\/pre><\/div>\n\n\n\n<p>Our code returns an error.<\/p>\n\n\n\n<p>This error is raised because we haven\u2019t passed \u201cself\u201d as an argument to our method. We fix this error by adding \u201cself\u201d as the first argument in the <code>change_year()<\/code> method: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>def change_year(self, year_released):\n\t\tself.year_released = year_released\n\t\tprint(&quot;{} was released in {}.&quot;.format(self.name, self.year_released))<\/pre><\/div>\n\n\n\n<p>Run our code again:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Happy Gilmore was released in 1996.<\/pre><\/div>\n\n\n\n<p>Our code runs successfully!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Scenario #2: Using \u201cself\u201d as an Argument in Another Argument<\/h2>\n\n\n\n<p>\u201cself\u201d is evaluated when a function is called. This means that you cannot have an argument that refers to \u201cself\u201d in the list of arguments specified in a function call.<br><\/p>\n\n\n\n<p>Update our \u201cyear_released\u201d method so that, if a different year of release is not specified, a message is printed to the console telling us that the year of a movie has not been changed.<br><\/p>\n\n\n\n<p>We can do this by setting a default argument in our code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>def change_year(self, year_released=self.year_released):\n\tif year_released != self.year_released:\n\t\tself.year_released = year_released\n\t\tprint(&quot;{} was released in {}.&quot;.format(self.name, self.year_released))\n\telse:\n\t\tprint(&quot;This movie has not been changed.&quot;)\n\n\tprint(year_released)<\/pre><\/div>\n\n\n\n<p>\u201cyear_released\u201d now has the default value of \u201cself.year_released\u201d. This means if we do not specify a value to which the year should be changed, a default value is set. If we do specify a value, the value we specify is used instead of the default.<br><\/p>\n\n\n\n<p>If the value we specify is not equal to the value of \u201cself.year_released\u201d, the value of \u201cself.year_released\u201d is changed. Otherwise, a message is printed to the console telling the user that the movie has not been changed.<br><\/p>\n\n\n\n<p>After our <code>if<\/code> statement has been evaluated, the value of \u201cyear_released\u201d is printed to the console.<br><\/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 1, in &lt;module&gt;\n\tclass Movie:\n  File &quot;main.py&quot;, line 6, in Movie\n\tdef change_year(self, year_released=self.year_released):\nNameError: name 'self' is not defined<\/pre><\/div>\n\n\n\n<p>Our code raises an error. This is because we\u2019ve tried to use \u201cself\u201d in another argument in our list of arguments.<br><\/p>\n\n\n\n<p>We can fix this error by setting the value of the \u201cyear_released\u201d <a href=\"https:\/\/careerkarma.com\/blog\/python-variables\/\">variable<\/a> to \u201cself.year_released\u201d inside our function instead of in our list of arguments:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>def change_year(self, year_released=None):\n\tif year_released != self.year_released:\n\t\tself.year_released = year_released\n\t\tprint(&quot;{} was released in {}.&quot;.format(self.name, self.year_released))\n\telse:\n\t\tyear_released = self.year_released\n\t\tprint(&quot;This movie has not been changed.&quot;)\n\n\tprint(year_released)<\/pre><\/div>\n\n\n\n<p>In this code, we set \u201cyear_released\u201d to be equal to \u201cself.year_released\u201d if we do not specify a value for \u201cyear_released\u201d in our function call.<br><\/p>\n\n\n\n<p>Let\u2019s create a new Movie object to test out our code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>happy_gilmore = Movie(&quot;Happy Gilmore&quot;, 1995)\nhappy_gilmore.change_year(1996)<\/pre><\/div>\n\n\n\n<p>We have incorrectly specified the year Happy Gilmore was released as 1995. We need to change it using the <code>change_year()<\/code> method. Our code returns:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Happy Gilmore was released in 1996.\n1996<\/pre><\/div>\n\n\n\n<p>Our code was successfully executed. Let\u2019s test our code to see what happens if the value of \u201cyear_released\u201d is already equal to the one we specify in the <code>change_year()<\/code> method:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>happy_gilmore = Movie(&quot;Happy Gilmore&quot;, 1996)\nhappy_gilmore.change_year(1996)<\/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>This movie has not been changed.\n1996<\/pre><\/div>\n\n\n\n<p>Our code executes the <code>else<\/code> statement in our code and then tells us that the movie has not been changed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The \u201cNameError: name \u2018self\u2019 is not defined\u201d error is raised when you forget to specify \u201cself\u201d as a positional argument or when you use \u201cself\u201d in another argument in a list of arguments.<br><\/p>\n\n\n\n<p>You solve this error by making sure that all methods in a function that use \u201cself\u201d include \u201cself\u201d in their list of arguments. If that does not work, make sure that no arguments in a list of arguments depend on \u201cself\u201d for their default values.<br><\/p>\n\n\n\n<p>Now you\u2019re ready to solve this Python error like a <a href=\"https:\/\/careerkarma.com\/blog\/python-projects-beginners\/\">professional developer<\/a>!<\/p>\n","protected":false},"excerpt":{"rendered":"The value \u201cself\u201d is only available inside a method when a function is called and specified. You cannot access \u201cself\u201d in the arguments specified to a method, or inside a function without specifying \u201cself\u201d as an argument. Otherwise, you see the error \u201cNameError: name \u2018self\u2019 is not defined\u201d. In this guide, we talk about what&hellip;","protected":false},"author":240,"featured_media":21289,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[16578],"tags":[],"class_list":{"0":"post-21288","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.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python NameError: name \u2018self\u2019 is not defined Solution | Career Karma<\/title>\n<meta name=\"description\" content=\"On Career Karma, learn about the Python NameError: name \u2018self\u2019 is not defined, how the error works, and how to solve the 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-nameerror-name-self-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 \u2018self\u2019 is not defined Solution\" \/>\n<meta property=\"og:description\" content=\"On Career Karma, learn about the Python NameError: name \u2018self\u2019 is not defined, how the error works, and how to solve the error.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/python-nameerror-name-self-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-17T19:22:11+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:57:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/nikolay-tarashchenko-ep6Afz45gH0-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-self-is-not-defined\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-self-is-not-defined\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Python NameError: name \u2018self\u2019 is not defined Solution\",\"datePublished\":\"2020-08-17T19:22:11+00:00\",\"dateModified\":\"2023-12-01T11:57:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-self-is-not-defined\\\/\"},\"wordCount\":838,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-self-is-not-defined\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/nikolay-tarashchenko-ep6Afz45gH0-unsplash.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-self-is-not-defined\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-self-is-not-defined\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-self-is-not-defined\\\/\",\"name\":\"Python NameError: name \u2018self\u2019 is not defined Solution | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-self-is-not-defined\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-self-is-not-defined\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/nikolay-tarashchenko-ep6Afz45gH0-unsplash.jpg\",\"datePublished\":\"2020-08-17T19:22:11+00:00\",\"dateModified\":\"2023-12-01T11:57:59+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"On Career Karma, learn about the Python NameError: name \u2018self\u2019 is not defined, how the error works, and how to solve the error.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-self-is-not-defined\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-self-is-not-defined\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-self-is-not-defined\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/nikolay-tarashchenko-ep6Afz45gH0-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/nikolay-tarashchenko-ep6Afz45gH0-unsplash.jpg\",\"width\":1020,\"height\":680},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/python-nameerror-name-self-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 \u2018self\u2019 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 \u2018self\u2019 is not defined Solution | Career Karma","description":"On Career Karma, learn about the Python NameError: name \u2018self\u2019 is not defined, how the error works, and how to solve the 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-nameerror-name-self-is-not-defined\/","og_locale":"en_US","og_type":"article","og_title":"Python NameError: name \u2018self\u2019 is not defined Solution","og_description":"On Career Karma, learn about the Python NameError: name \u2018self\u2019 is not defined, how the error works, and how to solve the error.","og_url":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-self-is-not-defined\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-08-17T19:22:11+00:00","article_modified_time":"2023-12-01T11:57:59+00:00","og_image":[{"width":1020,"height":680,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/nikolay-tarashchenko-ep6Afz45gH0-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-self-is-not-defined\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-self-is-not-defined\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Python NameError: name \u2018self\u2019 is not defined Solution","datePublished":"2020-08-17T19:22:11+00:00","dateModified":"2023-12-01T11:57:59+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-self-is-not-defined\/"},"wordCount":838,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-self-is-not-defined\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/nikolay-tarashchenko-ep6Afz45gH0-unsplash.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/python-nameerror-name-self-is-not-defined\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-self-is-not-defined\/","url":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-self-is-not-defined\/","name":"Python NameError: name \u2018self\u2019 is not defined Solution | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-self-is-not-defined\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-self-is-not-defined\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/nikolay-tarashchenko-ep6Afz45gH0-unsplash.jpg","datePublished":"2020-08-17T19:22:11+00:00","dateModified":"2023-12-01T11:57:59+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"On Career Karma, learn about the Python NameError: name \u2018self\u2019 is not defined, how the error works, and how to solve the error.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-self-is-not-defined\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/python-nameerror-name-self-is-not-defined\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-self-is-not-defined\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/nikolay-tarashchenko-ep6Afz45gH0-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/08\/nikolay-tarashchenko-ep6Afz45gH0-unsplash.jpg","width":1020,"height":680},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/python-nameerror-name-self-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 \u2018self\u2019 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\/21288","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=21288"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/21288\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/21289"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=21288"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=21288"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=21288"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}