{"id":16920,"date":"2020-09-21T14:09:00","date_gmt":"2020-09-21T08:39:00","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/"},"modified":"2026-03-25T19:02:46","modified_gmt":"2026-03-25T13:32:46","slug":"classes-and-objects-in-python","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/","title":{"rendered":"Classes and Objects in Python"},"content":{"rendered":"\n<p>A Python class is a blueprint that defines attributes and methods for objects. An object is a specific instance created from that class.<\/p>\n\n\n\n<p>For example, a <code>Car<\/code> class defines what a car is: it has attributes like <code>color<\/code> and <code>make<\/code>, and methods like <code>start()<\/code> and <code>stop()<\/code>. A real car, like a red sedan, is an object of the <code>Car<\/code> class.<\/p>\n\n\n\n<p>Classes help you structure programs. They make your code easy to read and manage.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"why-use-classes-and-objects\">Why Use Classes and Objects?<\/h2>\n\n\n\n<p>Using classes and objects brings important benefits:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Organized Code:<\/strong> Classes group related data and functions. This makes your code cleaner.<\/li>\n\n\n\n<li><strong>Reusability:<\/strong> You define a class once. Then you create many objects from it. This saves you from writing duplicate code.<\/li>\n\n\n\n<li><strong>Data Encapsulation:<\/strong> Classes keep data and methods together. This protects your data.<\/li>\n\n\n\n<li><strong>Code Modularity:<\/strong> Each class can work on its own. This makes debugging easier.<\/li>\n<\/ul>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-title-link\">Python Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">In this course, you will learn the fundamentals of Python: from basic syntax to mastering data structures, loops, and functions. You will also explore OOP concepts and objects to build robust programs.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>11.5 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>51 Coding Exercises<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/master-python-programming\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"5-steps-to-use-classes-and-objects-in-python\">5 Steps to Use Classes and Objects in Python<\/h2>\n\n\n\n<p>Here\u2019s how to work with classes and objects in Python.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-1-define-a-class\">Step 1: Define a Class<\/h3>\n\n\n\n<p>You define a class with the <code>class<\/code> keyword. Class names typically start with an uppercase letter.<\/p>\n\n\n\n<p>Here's an example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Dog:\n    pass\n<\/pre><\/div>\n\n\n<p>This <code>Dog<\/code> class is empty. It is still a valid class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-2-add-attributes-to-a-class\">Step 2: Add Attributes to a Class<\/h3>\n\n\n\n<p>Attributes are variables that belong to a class or object. You can define them in the <code>__init__<\/code> method.<\/p>\n\n\n\n<p>The <code>__init__<\/code> method is a constructor. Python runs it automatically when you create a new object.<\/p>\n\n\n\n<p>Use <code>self<\/code> as the first parameter in methods. It refers to the object itself.<\/p>\n\n\n\n<p>Here\u2019s how to add attributes:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Dog:\n    def __init__(self, name, breed):\n        self.name = name    # Instance attribute\n        self.breed = breed  # Instance attribute\n\n    species = &quot;Canis familiaris&quot; # Class attribute\n<\/pre><\/div>\n\n\n<p>In this code:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>name<\/code> and <code>breed<\/code> are instance attributes. Each <code>Dog<\/code> object has its own name and breed.<\/li>\n\n\n\n<li><code>species<\/code> is a class attribute. All <code>Dog<\/code> objects share the same <code>species<\/code> value.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-3-add-methods-to-a-class\">Step 3: Add Methods to a Class<\/h3>\n\n\n\n<p>Methods are functions inside a class. They perform actions on the object's data.<\/p>\n\n\n\n<p>Here\u2019s how to add methods:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Dog:\n    def __init__(self, name, breed):\n        self.name = name\n        self.breed = breed\n\n    species = &quot;Canis familiaris&quot;\n\n    def bark(self):\n        print(f&quot;{self.name} says Woof!&quot;)\n\n    def describe(self):\n        print(f&quot;{self.name} is a {self.breed}.&quot;)\n<\/pre><\/div>\n\n\n<p>Now, the <code>Dog<\/code> class has <code>bark()<\/code> and <code>describe()<\/code> methods. These methods use the <code>name<\/code> and <code>breed<\/code> of a specific <code>Dog<\/code> object.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-4-create-objects-from-a-class\">Step 4: Create Objects from a Class<\/h3>\n\n\n\n<p>To create an object from a class, call the class name. Pass any arguments the <code>__init__<\/code> method needs.<\/p>\n\n\n\n<p>Here's how to create objects:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n# Create two Dog objects\nmy_dog = Dog(&quot;Buddy&quot;, &quot;Golden Retriever&quot;)\nyour_dog = Dog(&quot;Lucy&quot;, &quot;Labrador&quot;)\n\nprint(my_dog.name)   # Output: Buddy\nprint(your_dog.breed) # Output: Labrador\n<\/pre><\/div>\n\n\n<p>Now <code>my_dog<\/code> and <code>your_dog<\/code> are separate <code>Dog<\/code> objects. Each has its own attributes.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-5-access-attributes-and-call-methods\">Step 5: Access Attributes and Call Methods<\/h3>\n\n\n\n<p>You access an object's attributes and call its methods using a dot (<code>.<\/code>).<\/p>\n\n\n\n<p>Here\u2019s how to do it:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nmy_dog = Dog(&quot;Buddy&quot;, &quot;Golden Retriever&quot;)\n\n# Access attributes\nprint(my_dog.name)      # Output: Buddy\nprint(my_dog.species)   # Output: Canis familiaris\n\n# Call methods\nmy_dog.bark()           # Output: Buddy says Woof!\nmy_dog.describe()       # Output: Buddy is a Golden Retriever.\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"best-practices-for-classes-and-objects\">Best Practices for Classes and Objects<\/h2>\n\n\n\n<p>Follow these practices to write effective classes and objects:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Clear Names:<\/strong> Use descriptive names for classes, attributes, and methods.<\/li>\n\n\n\n<li><strong>Single Responsibility:<\/strong> Each class should do one main thing. This makes classes easier to manage.<\/li>\n\n\n\n<li><strong>Encapsulation:<\/strong> Keep data private when possible. Use methods to change data, not direct access.<\/li>\n\n\n\n<li><strong>Docstrings:<\/strong> Add docstrings to explain what your classes and methods do.<\/li>\n\n\n\n<li><strong>Understand <code>self<\/code>:<\/strong> Always put <code>self<\/code> as the first parameter in instance methods. It connects the method to its object.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"example-a-bank-account-class\">Example: A Bank Account Class<\/h2>\n\n\n\n<p>Here\u2019s a practical example of a <code>BankAccount<\/code> class:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass BankAccount:\n    &quot;&quot;&quot;Represents a simple bank account.&quot;&quot;&quot;\n    def __init__(self, account_number, owner_name, balance=0.0):\n        &quot;&quot;&quot;Initializes a new bank account.&quot;&quot;&quot;\n        self.account_number = account_number\n        self.owner_name = owner_name\n        self.balance = balance\n\n    def deposit(self, amount):\n        &quot;&quot;&quot;Deposits money into the account.&quot;&quot;&quot;\n        if amount &gt; 0:\n            self.balance += amount\n            print(f&quot;Deposited {amount:.2f}. New balance: {self.balance:.2f}&quot;)\n        else:\n            print(&quot;Deposit amount must be positive.&quot;)\n\n    def withdraw(self, amount):\n        &quot;&quot;&quot;Withdraws money from the account.&quot;&quot;&quot;\n        if amount &gt; 0 and self.balance &gt;= amount:\n            self.balance -= amount\n            print(f&quot;Withdrew {amount:.2f}. New balance: {self.balance:.2f}&quot;)\n        elif amount &amp;lt;= 0:\n            print(&quot;Withdrawal amount must be positive.&quot;)\n        else:\n            print(&quot;Insufficient funds.&quot;)\n\n    def get_balance(self):\n        &quot;&quot;&quot;Returns the current account balance.&quot;&quot;&quot;\n        return self.balance\n\n# Create an account\naccount1 = BankAccount(&quot;12345&quot;, &quot;Alice Smith&quot;, 1000.0)\n\n# Interact with the account\naccount1.deposit(200.0)\naccount1.withdraw(500.0)\naccount1.deposit(100.0)\naccount1.withdraw(1000.0)\n\n# Get the final balance\ncurrent_balance = account1.get_balance()\nprint(f&quot;Account {account1.account_number} balance: {current_balance:.2f}&quot;)\n<\/pre><\/div>\n\n\n<p>This <code>BankAccount<\/code> The class shows how to define attributes and methods. It demonstrates creating objects and using them.<\/p>\n\n\n\n<p>This practical example is great for showing real-world utility, making it a perfect spot to invite learners to build their own tools.<br><br>The Bank Account example illustrates how Python can handle real-world logic, much like a dynamic financial model in a spreadsheet. Mastering this level of programming allows you to automate repetitive tasks and manage data more efficiently. To practice building your own functional programs and to strengthen your core coding skills, consider signing up for a<strong> <\/strong>Free Python Course that guides you through these fundamental coding exercises step-by-step.<br><\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Free Course<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/python-fundamentals-for-beginners\" class=\"courses-cta-title-link\">Python Fundamentals for Beginners Free Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master Python basics, from variables to data structures and control flow. Solve real-time problems and build practical skills using Jupyter Notebook.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>13.5 hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>4.55<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/learn-for-free\/courses\/python-fundamentals-for-beginners\" class=\"courses-cta-button\">\n                Enroll for Free\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"next-step\">Next Step<\/h2>\n\n\n\n<p>While mastering classes and objects is essential for modular design, taking your skills to the next level requires understanding how to build efficient, industry-standard programs. <\/p>\n\n\n\n<p>The <strong>Learn Python with Generative AI<\/strong> course from <strong>Johns Hopkins Engineering Executive and Professional Education<\/strong> offers an accelerated pathway to move from foundational syntax to applied programming. <\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Johns Hopkins University<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/online.lifelonglearning.jhu.edu\/self-paced-online-python-with-generative-ai\" class=\"courses-cta-title-link\">Learn Python with Generative AI<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Learn Python programming fundamentals and apply Generative AI to write, debug, and refine code, progressing from foundational concepts to applied programming.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>Hands-on Learning<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>Duration: 10 Hours<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/online.lifelonglearning.jhu.edu\/self-paced-online-python-with-generative-ai\" class=\"courses-cta-button\">\n                Apply Now\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<p>By using ChatGPT as an interactive coding assistant, you can learn to write, debug, and refine modular code more effectively. This 10-hour, self-paced program ensures you can apply core features like functions and industry-standard packages to create professional-grade applications. Enroll now and start securing your coding skills in this AI-powered era.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A Python class is a blueprint that defines attributes and methods for objects. An object is a specific instance created from that class. For example, a Car class defines what a car is: it has attributes like color and make, and methods like start() and stop(). A real car, like a red sedan, is an [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":18716,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36796],"content_type":[],"class_list":["post-16920","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-python"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Python Classes and Objects with Examples<\/title>\n<meta name=\"description\" content=\"Learn Python classes and objects with clear examples. Understand how to define classes, add attributes and methods, and create objects.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Classes and Objects in Python\" \/>\n<meta property=\"og:description\" content=\"Learn Python classes and objects with clear examples. Understand how to define classes, add attributes and methods, and create objects.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2020-09-21T08:39:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-03-25T13:32:46+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/shutterstock_1188121216.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"667\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/classes-and-objects-in-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/classes-and-objects-in-python\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"Classes and Objects in Python\",\"datePublished\":\"2020-09-21T08:39:00+00:00\",\"dateModified\":\"2026-03-25T13:32:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/classes-and-objects-in-python\\\/\"},\"wordCount\":700,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/classes-and-objects-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/shutterstock_1188121216.jpg\",\"keywords\":[\"python\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/classes-and-objects-in-python\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/classes-and-objects-in-python\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/classes-and-objects-in-python\\\/\",\"name\":\"Python Classes and Objects with Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/classes-and-objects-in-python\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/classes-and-objects-in-python\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/shutterstock_1188121216.jpg\",\"datePublished\":\"2020-09-21T08:39:00+00:00\",\"dateModified\":\"2026-03-25T13:32:46+00:00\",\"description\":\"Learn Python classes and objects with clear examples. Understand how to define classes, add attributes and methods, and create objects.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/classes-and-objects-in-python\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/classes-and-objects-in-python\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/classes-and-objects-in-python\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/shutterstock_1188121216.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/08\\\/shutterstock_1188121216.jpg\",\"width\":1000,\"height\":667,\"caption\":\"classes and objects in python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/classes-and-objects-in-python\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Classes and Objects in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Python Classes and Objects with Examples","description":"Learn Python classes and objects with clear examples. Understand how to define classes, add attributes and methods, and create objects.","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:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/","og_locale":"en_US","og_type":"article","og_title":"Classes and Objects in Python","og_description":"Learn Python classes and objects with clear examples. Understand how to define classes, add attributes and methods, and create objects.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2020-09-21T08:39:00+00:00","article_modified_time":"2026-03-25T13:32:46+00:00","og_image":[{"width":1000,"height":667,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/shutterstock_1188121216.jpg","type":"image\/jpeg"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"Classes and Objects in Python","datePublished":"2020-09-21T08:39:00+00:00","dateModified":"2026-03-25T13:32:46+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/"},"wordCount":700,"commentCount":1,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/shutterstock_1188121216.jpg","keywords":["python"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/","url":"https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/","name":"Python Classes and Objects with Examples","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/shutterstock_1188121216.jpg","datePublished":"2020-09-21T08:39:00+00:00","dateModified":"2026-03-25T13:32:46+00:00","description":"Learn Python classes and objects with clear examples. Understand how to define classes, add attributes and methods, and create objects.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/shutterstock_1188121216.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/shutterstock_1188121216.jpg","width":1000,"height":667,"caption":"classes and objects in python"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/classes-and-objects-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"Classes and Objects in Python"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/shutterstock_1188121216.jpg",1000,667,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/shutterstock_1188121216-150x150.jpg",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/shutterstock_1188121216-300x200.jpg",300,200,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/shutterstock_1188121216-768x512.jpg",768,512,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/shutterstock_1188121216.jpg",1000,667,false],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/shutterstock_1188121216.jpg",1000,667,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/shutterstock_1188121216.jpg",1000,667,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/shutterstock_1188121216.jpg",640,427,false],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/shutterstock_1188121216.jpg",96,64,false],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2020\/08\/shutterstock_1188121216.jpg",150,100,false]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":1,"uagb_excerpt":"A Python class is a blueprint that defines attributes and methods for objects. An object is a specific instance created from that class. For example, a Car class defines what a car is: it has attributes like color and make, and methods like start() and stop(). A real car, like a red sedan, is an&hellip;","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/16920","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=16920"}],"version-history":[{"count":16,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/16920\/revisions"}],"predecessor-version":[{"id":116946,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/16920\/revisions\/116946"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/18716"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=16920"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=16920"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=16920"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=16920"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}