{"id":42014,"date":"2021-08-01T15:52:59","date_gmt":"2021-08-01T15:52:59","guid":{"rendered":"https:\/\/www.oracletutoring.ca\/blog\/?p=42014"},"modified":"2021-08-01T15:53:01","modified_gmt":"2021-08-01T15:53:01","slug":"python-self-and-the-implicit-argument","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/python-self-and-the-implicit-argument\/","title":{"rendered":"Python: self and the implicit argument"},"content":{"rendered":"\n<h2>Self-tutoring about Python: the tutor mentions the <em>self<\/em> concept.<\/h2>\n<p>\nTo Python, when you call an ordinary class method (as opposed to a static one), the object whose method is being called is an implicit parameter. You can call it externally without mentioning that. Internally, however, it needs to be there.\n<\/p>\n<p style=\"font-family:monospace\">\nclass Class0:<br\/>\n<span style=\"margin-left:3em\">def hello(self):<\/span> #self means this object<br\/>\n<span style=\"margin-left:6em\">print(&#8220;hello from Class0&#8221;)<br\/>\n<\/p>\n<p>\nWhen you make an object of Class0, like so:<br\/>\n<span style=\"font-family:monospace\">a=Class0()<\/span><br\/>\nyou can then call its &#8220;hello&#8221; method without giving any parameters:<br\/>\n<span style=\"font-family:monospace\">a.hello()<\/span>\n<\/p>\n<p>Within the class definition, people typically use <em>self<\/em> as the parameter that represents the object. Yet, <em>self<\/em> is not a keyword; <em>duck<\/em> would work equally well, so far as I know.<\/p>\n<p>Source:<\/p>\n<p><a href=\"https:\/\/pythonexamples.org\/python-typeerror-method-takes-0-positional-arguments-but-1-was-given\/\">pythonexamples.org<\/a><\/p>\n<p><a href=\"https:\/\/stackoverflow.com\/questions\/7721920\/when-do-you-use-self-in-python\">stackoverflow.com<\/a><\/p>\nJack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.\n","protected":false},"excerpt":{"rendered":"<p>Self-tutoring about Python: the tutor mentions the self concept. To Python, when you call an ordinary class method (as opposed to a static one), the object whose method is being called is an implicit parameter. You can call it externally &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/python-self-and-the-implicit-argument\/\"> <span class=\"screen-reader-text\">Python: self and the implicit argument<\/span> Read More &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1856],"tags":[],"class_list":["post-42014","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/42014","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/comments?post=42014"}],"version-history":[{"count":6,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/42014\/revisions"}],"predecessor-version":[{"id":42020,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/42014\/revisions\/42020"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=42014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=42014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=42014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}