{"id":784,"date":"2024-08-11T22:31:29","date_gmt":"2024-08-11T17:31:29","guid":{"rendered":"https:\/\/augurytech.co.uk\/courses\/?p=784"},"modified":"2024-10-05T09:04:51","modified_gmt":"2024-10-05T04:04:51","slug":"python-classes","status":"publish","type":"post","link":"https:\/\/augurytech.co.uk\/courses\/python\/python-classes\/","title":{"rendered":"Python: Classes"},"content":{"rendered":"\n<div class=\"wp-block-group is-vertical is-content-justification-stretch is-layout-flex wp-container-core-group-is-layout-353c4f5a wp-block-group-is-layout-flex\">\n<p><strong>Python <\/strong>is an &#8220;object-oriented programming language.&#8221; Almost all the code is implemented using a special construct called <strong>classes<\/strong>.<br>Programmers use <strong>classes<\/strong> to keep related things together. This is done using the keyword &#8220;<strong>class<\/strong>&#8220;.<\/p>\n<\/div>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-group is-vertical is-content-justification-stretch is-layout-flex wp-container-core-group-is-layout-353c4f5a wp-block-group-is-layout-flex\">\n<h3 class=\"wp-block-heading\">What is a Class?<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A Class is a model<\/li>\n\n\n\n<li>A class is a blueprint(map) of anything<\/li>\n\n\n\n<li>A class is a template<\/li>\n\n\n\n<li>A class may also be defined as something that can be followed to<\/li>\n\n\n\n<li>create objects and instances<\/li>\n<\/ul>\n<\/div>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-group is-vertical is-content-justification-stretch is-layout-flex wp-container-core-group-is-layout-353c4f5a wp-block-group-is-layout-flex\">\n<h3 class=\"wp-block-heading\">Writing a Class<\/h3>\n\n\n\n<p><strong>Python uses the keyword &#8220;class&#8221; to define a class<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Class Car():\n# body of class Car<\/code><\/pre>\n<\/div>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-group is-vertical is-content-justification-stretch is-layout-flex wp-container-core-group-is-layout-353c4f5a wp-block-group-is-layout-flex\">\n<h3 class=\"wp-block-heading\">Writing a Class<\/h3>\n\n\n\n<p><strong>Python uses the keyword &#8220;class&#8221; to define a class<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>Class Car():\n      # body of class Car<\/strong><\/code><\/pre>\n<\/div>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-group is-vertical is-content-justification-stretch is-layout-flex wp-container-core-group-is-layout-353c4f5a wp-block-group-is-layout-flex\">\n<h3 class=\"wp-block-heading\">What does the actual class hold??<\/h3>\n\n\n\n<p>A class may hold attributes (variables)<br>A class may hold behaviours (functions)<br><strong>Example:<\/strong><br>A car&#8217;s colour, model, and seating capacity are attributes of the car.<br>A car can run, stop, speed_up, and speed_down are behaviours of a car<\/p>\n<\/div>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-group is-vertical is-content-justification-stretch is-layout-flex wp-container-core-group-is-layout-353c4f5a wp-block-group-is-layout-flex\">\n<h3 class=\"wp-block-heading\">Classes: Creating an instance<\/h3>\n\n\n\n<p><strong>Almost everything in Python is an object, with its properties and methods.<br>Objects are made following its class means if an objects belongs to a class it must have been following the requirements set by the class<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>class Car():\n     # define a class body\n         # attributes and behaviours<\/strong>\n<strong>\n# Creating objects\/instance of Car class\n    car1 = Car()\n    car2 = Car()<\/strong><\/code><\/pre>\n<\/div>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Python is an &#8220;object-oriented programming language.&#8221; Almost all the code is implemented using a special construct called classes.Programmers use classes to keep related things together. This is done using the keyword &#8220;class&#8220;. What is a Class? Writing a Class Python uses the keyword &#8220;class&#8221; to define a class Writing a Class Python uses the keyword [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"wp-custom-template-python","format":"standard","meta":{"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[5],"tags":[],"class_list":{"0":"post-784","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python"},"_links":{"self":[{"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/posts\/784","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/comments?post=784"}],"version-history":[{"count":11,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/posts\/784\/revisions"}],"predecessor-version":[{"id":800,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/posts\/784\/revisions\/800"}],"wp:attachment":[{"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/media?parent=784"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/categories?post=784"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/tags?post=784"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}