{"id":24795,"date":"2023-03-25T07:11:17","date_gmt":"2023-03-25T01:41:17","guid":{"rendered":"https:\/\/tocxten.com\/?page_id=24795"},"modified":"2023-03-25T07:14:39","modified_gmt":"2023-03-25T01:44:39","slug":"9-classes-and-objects","status":"publish","type":"page","link":"https:\/\/tocxten.com\/index.php\/9-classes-and-objects\/","title":{"rendered":"9.Classes and Objects"},"content":{"rendered":"\n<p class=\"has-cyan-bluish-gray-background-color has-background\"><strong>Syllabus <\/strong><\/p>\n\n\n\n<p><strong>9.1 Classes and objects<\/strong>: Programmer-defined types, Attributes, Rectangles, Instances as return<br>values, Objects are mutable, Copying,<\/p>\n\n\n\n<p><strong>9.2 Classes and functions: <\/strong>Time, Pure functions, Modifiers, Prototyping versus planning,<\/p>\n\n\n\n<p><strong>9.3 Classes and methods<\/strong>:  Object-oriented features, Printing objects, Another example, A more<br>complicated example,The __init__ method, The <strong>str<\/strong> method, Operator overloading, Type-based<br>dispatch, Polymorphism, Interface and implementation,<\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background has-large-font-size\"><strong>9.1 Classes and objects <\/strong><\/p>\n\n\n\n<p>Python is an object oriented programming language. Class is a abstract data type which can be defined as a template or blueprint that describes the behavior \/ state that the object of its type support. <\/p>\n\n\n\n<p><strong>An object is an instance of class . Objects<\/strong>&nbsp;have states and behaviors. <\/p>\n\n\n\n<p><strong>Example:<\/strong> A dog has states &#8211; color, name, breed as well as behaviors \u2013 wagging the tail, barking, eating.<\/p>\n\n\n\n<p><strong>Object is <\/strong>simply a collection of <strong><em>data (variables) and methods (functions) that act on those data<\/em><\/strong>. <strong><em>The process of creating this object is called instantiation<\/em><\/strong><\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background\"><strong>Defining a Class in Python <\/strong>: <\/p>\n\n\n\n<p>We define a class using the keyword <strong><em>class.<\/em><\/strong> The first string is called <strong><em>docstring and has a brief description about the class<\/em><\/strong>. Although not mandatory, this is recommended. <strong><em>A class&nbsp; attributes are data members( variables)&nbsp; and&nbsp; functions<\/em>.<\/strong><\/p>\n\n\n\n<p class=\"has-light-green-cyan-background-color has-background has-medium-font-size\"><strong>Syntax : <\/strong><\/p>\n\n\n\n<p>The <strong><em>class<\/em><\/strong> statement creates a new class definition. The name of the class immediately follows the keyword <strong><em>class<\/em><\/strong> followed by a colon as follows \u2212<\/p>\n\n\n\n<p><strong>class&nbsp;&nbsp; <\/strong><strong>ClassName:<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \u201c\u201d\u201d<strong><em>Optional class documentation string&#8217; class_suite\u201d\u201d\u201d<\/em><\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <strong>class_suite<\/strong><\/p>\n\n\n\n<p>\u2022The class has a documentation string, which can be accessed via <strong><em>ClassName.__doc__<\/em><\/strong><strong>.<\/strong><\/p>\n\n\n\n<p>\u2022The <strong><em>class_suite<\/em><\/strong> consists of all the component statements defining class members, data attributes and method.<\/p>\n\n\n\n<p class=\"has-light-green-cyan-background-color has-background\"><strong>Example 1<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Syllabus 9.1 Classes and objects: Programmer-defined types, Attributes, Rectangles, Instances as returnvalues, Objects are mutable, Copying, 9.2 Classes and functions: Time, Pure functions, Modifiers, Prototyping versus planning, 9.3 Classes and&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":"","_links_to":"","_links_to_target":""},"class_list":["post-24795","page","type-page","status-publish","hentry"],"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/pages\/24795","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/comments?post=24795"}],"version-history":[{"count":1,"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/pages\/24795\/revisions"}],"predecessor-version":[{"id":24797,"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/pages\/24795\/revisions\/24797"}],"wp:attachment":[{"href":"https:\/\/tocxten.com\/index.php\/wp-json\/wp\/v2\/media?parent=24795"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}