{"id":106,"date":"2026-03-02T08:18:13","date_gmt":"2026-03-02T03:18:13","guid":{"rendered":"https:\/\/gigz.pk\/python\/?post_type=lesson&#038;p=106"},"modified":"2026-03-15T17:08:23","modified_gmt":"2026-03-15T12:08:23","slug":"methods","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/python\/lesson\/methods\/","title":{"rendered":"Methods"},"content":{"rendered":"\n<p>n Object-Oriented Programming (OOP), a <strong>method<\/strong> is a function that is defined inside a class.<\/p>\n\n\n\n<p>Methods define the behavior of an object.<\/p>\n\n\n\n<p>If variables represent the data of an object, methods represent the actions of that object.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Basic Syntax<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">class ClassName:<br>    def method_name(self):<br>        # code block<\/pre>\n\n\n\n<p><code>self<\/code> refers to the current object that is calling the method.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Example of a Simple Method<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">class Student:<br>    def greet(self):<br>        print(\"Hello Student\")s1 = Student()<br>s1.greet()<\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Hello Student<\/pre>\n\n\n\n<p>Here:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>greet()<\/code> is a method<\/li>\n\n\n\n<li>It is called using the object <code>s1<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Method with Parameters<\/strong><\/h2>\n\n\n\n<p>Methods can also accept additional parameters.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">class Student:<br>    def greet(self, name):<br>        print(\"Hello\", name)s1 = Student()<br>s1.greet(\"Hira\")<\/pre>\n\n\n\n<p>Output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Hello Hira<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Types of Methods in Python<\/strong><\/h2>\n\n\n\n<p>There are mainly three types of methods:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. Instance Methods<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Work with instance variables<\/li>\n\n\n\n<li>Must use <code>self<\/code><\/li>\n\n\n\n<li>Called using object<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">class Student:<br>    def __init__(self, name):<br>        self.name = name    def display(self):<br>        print(self.name)s1 = Student(\"Hira\")<br>s1.display()<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. Class Methods<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Work with class variables<\/li>\n\n\n\n<li>Use <code>@classmethod<\/code> decorator<\/li>\n\n\n\n<li>Use <code>cls<\/code> instead of <code>self<\/code><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">class Student:<br>    school = \"GIGZ Academy\"    @classmethod<br>    def show_school(cls):<br>        print(cls.school)Student.show_school()<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. Static Methods<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Do not use instance or class variables<\/li>\n\n\n\n<li>Use <code>@staticmethod<\/code> decorator<\/li>\n\n\n\n<li>No <code>self<\/code> or <code>cls<\/code><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">class Math:<br>    @staticmethod<br>    def add(a, b):<br>        return a + bprint(Math.add(5, 3))<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Difference Between Method Types<\/strong><\/h2>\n\n\n\n<p>Instance Method<br>Uses object data<br>Requires <code>self<\/code><br>Called using object<\/p>\n\n\n\n<p>Class Method<br>Uses class data<br>Requires <code>cls<\/code><br>Called using class<\/p>\n\n\n\n<p>Static Method<br>Does not use class or object data<br>No <code>self<\/code> or <code>cls<\/code><br>Called using class<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Key Takeaway<\/strong><\/h2>\n\n\n\n<p>Methods define what an object can do.<br>They help organize code inside classes and make programs structured, reusable, and easy to manage.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/python\/\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">OBJECT ORIENTED PROGRAMMING IN PYTHON (OOP) > OOP Basics > Methods<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1773576447554\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n","protected":false},"menu_order":50,"template":"","class_list":["post-106","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Methods - One Language. Endless Possibilities<\/title>\n<meta name=\"description\" content=\"Learn Python OOP methods: instance, class, and static methods. Understand self, cls, and decorators with clear examples.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/python\/lesson\/methods\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Methods - One Language. Endless Possibilities\" \/>\n<meta property=\"og:description\" content=\"Learn Python OOP methods: instance, class, and static methods. Understand self, cls, and decorators with clear examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/python\/lesson\/methods\/\" \/>\n<meta property=\"og:site_name\" content=\"One Language. Endless Possibilities\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-15T12:08:23+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/methods\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/methods\\\/\",\"name\":\"Methods - One Language. Endless Possibilities\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\"},\"datePublished\":\"2026-03-02T03:18:13+00:00\",\"dateModified\":\"2026-03-15T12:08:23+00:00\",\"description\":\"Learn Python OOP methods: instance, class, and static methods. Understand self, cls, and decorators with clear examples.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/methods\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/methods\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/lesson\\\/methods\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"OBJECT ORIENTED PROGRAMMING IN PYTHON (OOP) > OOP Basics > Methods\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/python\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/python\\\/\",\"name\":\"One Language. Endless Possibilities\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/python\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Methods - One Language. Endless Possibilities","description":"Learn Python OOP methods: instance, class, and static methods. Understand self, cls, and decorators with clear examples.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/python\/lesson\/methods\/","og_locale":"en_US","og_type":"article","og_title":"Methods - One Language. Endless Possibilities","og_description":"Learn Python OOP methods: instance, class, and static methods. Understand self, cls, and decorators with clear examples.","og_url":"https:\/\/gigz.pk\/python\/lesson\/methods\/","og_site_name":"One Language. Endless Possibilities","article_modified_time":"2026-03-15T12:08:23+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/python\/lesson\/methods\/","url":"https:\/\/gigz.pk\/python\/lesson\/methods\/","name":"Methods - One Language. Endless Possibilities","isPartOf":{"@id":"https:\/\/gigz.pk\/python\/#website"},"datePublished":"2026-03-02T03:18:13+00:00","dateModified":"2026-03-15T12:08:23+00:00","description":"Learn Python OOP methods: instance, class, and static methods. Understand self, cls, and decorators with clear examples.","breadcrumb":{"@id":"https:\/\/gigz.pk\/python\/lesson\/methods\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/python\/lesson\/methods\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/python\/lesson\/methods\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/python\/"},{"@type":"ListItem","position":2,"name":"OBJECT ORIENTED PROGRAMMING IN PYTHON (OOP) > OOP Basics > Methods"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/python\/#website","url":"https:\/\/gigz.pk\/python\/","name":"One Language. Endless Possibilities","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/python\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson\/106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/python\/wp-json\/wp\/v2\/media?parent=106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}