{"id":526,"date":"2018-03-20T03:53:09","date_gmt":"2018-03-20T03:53:09","guid":{"rendered":"http:\/\/shijuvarghese.com\/?p=526"},"modified":"2019-08-12T08:16:18","modified_gmt":"2019-08-12T08:16:18","slug":"python-programming-1-object-oriented-programming","status":"publish","type":"post","link":"http:\/\/shijuvarghese.com\/?p=526","title":{"rendered":"Python programming 2: Object Oriented Programming"},"content":{"rendered":"<p>Python is a hight level programming language that supports Object Oriented Programming. The concepts one should be familiar is <strong>Class<\/strong>, <strong>Objects<\/strong> and <strong>instances<\/strong>, <strong>methods<\/strong> or <strong>functions<\/strong>, etc. Thus tutorial is aimed to introduce OOP using Python to audience <em>that are already familiar<\/em> with these concepts using any other OOP language such as Java, C++, etc<\/p>\n<p><strong>=======<\/strong><br \/>\n<em>#!\/usr\/bin\/python<\/em><\/p>\n<p><em>class MyVehicle:<\/em><br \/>\n<em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 #The __init__ function. The constructor of the class.<\/em><\/p>\n<p><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 #<\/em>The &#8220;self&#8221; variable is needed by default even if there are no variables to be passed.<\/p>\n<p><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 def __init__(self, theBrand, theModel): <\/em><br \/>\n<em> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0self.theBrand = theBrand<\/em><br \/>\n<em> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0self.theModel = theModel<\/em><\/p>\n<p><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0def speed(self, mySpeed):<\/em><br \/>\n<em> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0print(&#8220;My &#8221; + self.theBrand +\u00a0&#8221; &#8221; + self.theModel + &#8221; can go at a speed of &#8221; + str(mySpeed))<\/em><\/p>\n<p><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0def theType(self, theType):<\/em><br \/>\n<em> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0print(&#8220;I am of the type &#8221; + str(theType))<\/em><br \/>\n<em>def main():<\/em><br \/>\n<em> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0myCar = MyVehicle(&#8216;Honda&#8217;, &#8216;Accord&#8217;)<\/em><br \/>\n<em> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0myCar.speed(&#8217;60 kmh&#8217;)<\/em><\/p>\n<p><em>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0myNextCar = MyVehicle(&#8216;Jeep&#8217;, &#8216;Wrangler&#8217;)<\/em><br \/>\n<em> \u00a0 \u00a0 \u00a0 \u00a0 \u00a0\u00a0myNextCar.speed(&#8217;40 kmh&#8217;)<\/em><\/p>\n<p><em>main()<\/em><br \/>\n<strong>=======<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Python is a hight level programming language that supports Object Oriented Programming. The concepts one should be familiar is Class, Objects and instances, methods or <a class=\"mh-excerpt-more\" href=\"http:\/\/shijuvarghese.com\/?p=526\" title=\"Python programming 2: Object Oriented Programming\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":518,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,22,27],"tags":[],"class_list":["post-526","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops","category-programming","category-python"],"_links":{"self":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=526"}],"version-history":[{"count":8,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/526\/revisions"}],"predecessor-version":[{"id":864,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/526\/revisions\/864"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/media\/518"}],"wp:attachment":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=526"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}