{"id":48303,"date":"2024-11-06T19:54:24","date_gmt":"2024-11-06T19:54:24","guid":{"rendered":"https:\/\/www.oracletutoring.ca\/blog\/?p=48303"},"modified":"2024-11-06T19:54:25","modified_gmt":"2024-11-06T19:54:25","slug":"comp-sci-python-class-methods","status":"publish","type":"post","link":"https:\/\/www.oracletutoring.ca\/blog\/comp-sci-python-class-methods\/","title":{"rendered":"Comp sci: Python: class methods"},"content":{"rendered":"\n<h2>Self-tutoring about Python coding: the tutor mentions an observation about Python class methods.<\/h2>\n<p>\nA Python class method can be called by referencing its containing class name rather than an instance. Such a method might be called via classname.the_method(). However, it&#8217;s the definition of the class method that&#8217;s the point herein.<\/p>\n<p>\nOne might see a class method declaration with the decorator &commat;classmethod just above it, then with (cls) as its first argument, where (self) would be for an object method. My experience is that the decorator &commat;classmethod is necessary, at least for IDLE to run the method as desired. However, also in my experience, (cls) can be swapped out with (something_else) and the class method will still run the same.<\/p>\n<p>Source:<\/p>\n<p><a href=\"https:\/\/www.youtube.com\/watch?v=JeznW_7DlB0\">YouTube: Tech With Tim: Python Object Oriented Programming (OOP) &#8211; For Beginners<\/a><\/p>\nJack of <a href=\"https:\/\/www.oracletutoring.ca\">Oracle Tutoring by Jack and Diane,<\/a> Campbell River, BC.\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Self-tutoring about Python coding: the tutor mentions an observation about Python class methods. A Python class &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/www.oracletutoring.ca\/blog\/comp-sci-python-class-methods\/\"> <span class=\"screen-reader-text\">Comp sci: Python: class methods<\/span> Read more \u2192<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[105],"tags":[3447,3446,930],"class_list":["post-48303","post","type-post","status-publish","format-standard","hentry","category-computer-science","tag-classmethod-decorator","tag-decorators","tag-python"],"_links":{"self":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/48303","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=48303"}],"version-history":[{"count":5,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/48303\/revisions"}],"predecessor-version":[{"id":48308,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/posts\/48303\/revisions\/48308"}],"wp:attachment":[{"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/media?parent=48303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/categories?post=48303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.oracletutoring.ca\/blog\/wp-json\/wp\/v2\/tags?post=48303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}