

{"id":6118,"date":"2018-01-19T07:51:33","date_gmt":"2018-01-19T02:21:33","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=6118"},"modified":"2026-04-28T11:15:00","modified_gmt":"2026-04-28T05:45:00","slug":"python-class","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-class\/","title":{"rendered":"Python Class &#8211; Object &amp; Attributes Belonging to Class in Python"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:1278,&quot;href&quot;:&quot;https:\\\/\\\/techvidvan.com\\\/courses\\\/python-course-english&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20250713145243\\\/https:\\\/\\\/techvidvan.com\\\/courses\\\/python-course-english\\\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-09 04:35:05&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2025-12-12 05:42:20&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2025-12-15 05:49:39&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2025-12-18 06:05:40&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2025-12-21 06:38:49&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2025-12-24 07:58:25&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2025-12-27 08:14:01&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2025-12-30 09:23:27&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-01-02 13:50:09&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-01-05 14:45:45&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-01-08 15:40:20&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-01-11 17:38:53&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-01-14 20:22:22&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-01-18 03:46:37&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-01-21 05:38:02&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-01-24 07:35:25&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-01-27 08:15:24&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-01-30 15:09:25&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-03 06:31:54&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-06 07:30:29&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-09 08:26:08&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-12 11:17:37&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-15 14:03:28&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-18 14:13:43&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-21 15:29:57&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-24 16:17:25&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-02-28 07:00:57&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-03 07:20:03&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-06 11:10:42&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-09 13:00:48&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-12 13:03:00&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-15 19:32:01&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-18 23:50:01&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-22 02:44:11&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-25 06:28:30&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-28 06:54:17&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-03-31 06:59:56&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-03 08:00:46&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-06 12:20:22&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-09 14:25:59&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-12 15:18:36&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-16 02:03:12&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-19 07:06:10&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-22 07:12:30&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-25 09:23:03&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-04-28 10:36:26&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-05-01 11:53:00&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-05-04 12:01:26&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-05-07 12:36:14&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-05-10 15:18:07&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-05-13 16:14:13&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-05-16 17:13:30&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-05-20 03:50:51&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-05-23 04:11:07&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-05-26 04:55:32&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-05-29 07:41:02&quot;,&quot;http_code&quot;:403},{&quot;date&quot;:&quot;2026-06-01 11:38:39&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2026-06-04 17:19:39&quot;,&quot;http_code&quot;:403}],&quot;broken&quot;:true,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-04 17:19:39&quot;,&quot;http_code&quot;:403},&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p>In this Python Class tutorial, we are going to explore Python Classes. how they work and how to access.<\/p>\n<p>On the other hand, we will discuss what is the Python Object and different attributes that belong to a Python Class.<\/p>\n<p>At last, we cover how we can delete an object, attributes, or a class in Python.<\/p>\n<p>Like we\u2019ve often said, Python is an object-oriented programming language. This means it focuses on objects instead of procedures. An object can model the real world.<\/p>\n<p>So, let&#8217;s start Python Class and Object Tutorial.<\/p>\n<h3>What is Python Class?<\/h3>\n<p>A class is a blueprint for objects- one class for any number of objects of that type. You can also call it an abstract data type.<\/p>\n<p>A class in Python is like a recipe. It tells Python what parts an object should have and what it can do. When you write class Dog:, you give a plan that every dog object will follow. This plan can list data, such as name, and actions, such as bark().<\/p>\n<p>Creating a class also lets you reuse work. If tomorrow you need a Cat class, much of the logic from Dog carries over. You only tweak what is different. This reuse saves time and avoids errors.<\/p>\n<h3>Why Python class?<\/h3>\n<ul>\n<li><strong>Organization:<\/strong> It keeps relevant data and functions together so that the long programs can easily be maintained.<\/li>\n<li><strong>Reusable:<\/strong> Many objects can be created using one class without using the same code.<\/li>\n<li><strong>Inheritance:<\/strong> A new class can take the code from the existing code, so the code can be reused and maintained properly.<\/li>\n<\/ul>\n<p>Let&#8217;s see the classes in Python explained in detail.<\/p>\n<h3>Python Class Syntax<\/h3>\n<h4>1. Defining a Python Class<\/h4>\n<p>To define a class in <a href=\"https:\/\/techvidvan.com\/courses\/python-course-english\/\">python<\/a> programming, we use the \u2018class\u2019 keyword. This is like we use \u2018def\u2019 to define a function in Python.<\/p>\n<p>And like a function, a Python3 class may have a docstring as well.<\/p>\n<p>We can do this to write a couple of lines explaining what the class does. To focus on the syntax here, we will pass in a \u2018pass\u2019 statement in its body for now.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; class fruit:\r\n            \"\"\"\r\n            This Python3 class creates instances of fruits\r\n            \"\"\"<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Pass<\/div>\n<p>As soon as we define a class, a Python class object is created.<\/p>\n<p>But remember, you can only name a class according to the identifier naming rules as we discussed in our tutorial on Python Variables.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; fruit<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&lt;class &#8216;__main__.fruit&#8217;&gt; #The class object<\/div>\n<p>A Python class may have attributes and methods to execute on that data. We declare\/define these in the usual way.<\/p>\n<p>Let\u2019s take an example.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; class fruit: \r\n           \"\"\"\r\n           This class creates instances of fruits\r\n           \"\"\"\r\n           color=''\r\n           def sayhi(self):\r\n                    print(\"Hi\")\r\n\r\n&gt;&gt;&gt; orange=fruit()<\/pre>\n<p>Here, color is an attribute, and sayhi() is a method to call on an object of class fruit.<\/p>\n<p>You can also define a regular first-class function inside a method, but not outside it in a Python class.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; class try1:\r\n         def mymethod(self):\r\n                  def sayhello():\r\n                           print(\"Hello\")\r\n                  print(\"Hi\")\r\n                  sayhello()\r\n\r\n&gt;&gt;&gt; obj1=try1()\r\n&gt;&gt;&gt; obj1.mymethod()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>Hi<\/p>\n<p>Hello<\/p>\n<\/div>\n<p>You can also create an attribute on the fly.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; orange.shape='Round'\r\n&gt;&gt;&gt; orange.shape<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;Round&#8217;<\/div>\n<h4>2. Accessing Python Class Members<\/h4>\n<p>To access the members of a Python class, we use the dot operator. Let\u2019s create an orange object for our fruit class.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; orange=fruit()<\/pre>\n<p>Now, let\u2019s access the color attribute for orange.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; orange.color<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8220;<\/div>\n<p>This returns an empty string because that is what we specified in the class definition.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; orange.sayhi()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">Hi<\/div>\n<p>Here, we called the method sayhi() on orange. A method may take arguments, if defined that way.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; class fruit:\r\n          def size(self,x):\r\n                  print(f\"I am size {x}\")\r\n\r\n&gt;&gt;&gt; orange=fruit()\r\n&gt;&gt;&gt; orange.size(7)<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">I am size 7<\/div>\n<p>A Python class may also have some special attributes, like __doc__ for the docstring.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; fruit.__doc__<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;\\n\\tThis class creates instances of fruits\\n\\t&#8217;<\/div>\n<p>To get more insight into methods in Python, read up on Python Methods.<\/p>\n<p>But for now, we\u2019ll take an example including the __init__() magic method and the self parameter.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; class fruit:\r\n         def __init__(self,color,size):\r\n                  self.color=color\r\n                  self.size=size\r\n         def salutation(self):\r\n                  print(f\"I am {self.color} and a size {self.size}\")\r\n\r\n&gt;&gt;&gt; orange=fruit('Orange',7)\r\n&gt;&gt;&gt; orange.salutation()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">I am Orange and a size 7<\/div>\n<p>As you can see, the __init__() method is equivalent to a constructor in C++ or Java. It gets called every time we create an object of the class.<\/p>\n<p>Likewise, the self parameter is to tell the interpreter to deal with the current object. This is like the \u2018this\u2019 keyword in Java.<\/p>\n<p>But you don\u2019t have to call it \u2018self\u2019; you can call it anything. The object is passed as the first argument, fitting in for \u2018self\u2019.<\/p>\n<p>Here, orange.salutation() translates to fruit. salutation(orange).<\/p>\n<p>Also, salutation is a function object for the Python class, but a method object for the instance object \u2018orange\u2019.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; fruit.salutation<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&lt;function fruit.salutation at 0x0628FE40&gt;<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; orange.salutation<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&lt;bound method fruit.salutation of &lt;__main__.fruit object at 0x062835F0&gt;&gt;<\/div>\n<p>You can store a method object in a variable for later use.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; sayhi=orange.salutation\r\n&gt;&gt;&gt; sayhi()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">I am Orange and a size 7<\/div>\n<h3>What is the Python Object?<\/h3>\n<p>Now, how useful is a Python class without an object? If a class is an idea, an object is its execution.<\/p>\n<p>When we create an object, its __init__() method is called.<\/p>\n<p>And like we previously discussed, the object gets passed to the class through the function with the \u2018self\u2019 keyword.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; orange=fruit('Orange',7)<\/pre>\n<p>Here, we passed \u2018Orange\u2019 and 7 as values for the attributes color and size.<\/p>\n<p>We can also declare attributes for an object on the fly. See how.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; orange.shape='Round'\r\n&gt;&gt;&gt; orange.shape<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;Round&#8217;<\/div>\n<p>You can assign the values of an object in Python to another.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; apple=orange\r\n&gt;&gt;&gt; apple.color<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;Orange&#8217;<\/div>\n<p>We will check objects in detail in our next tutorial.<\/p>\n<h3>Attributes Belonging to Python Class<\/h3>\n<p>To explain this, we\u2019ll redefine the Python class fruit.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; class fruit:\r\n         size='Small'\r\n         def __init__(self,color,shape):\r\n                self.color=color\r\n                self.shape=shape\r\n         def salutation(self):\r\n                print(f\"I am {self.color} and a shape {self.shape}\")<\/pre>\n<p>Here, the attribute \u2018size\u2019 belongs to the class, but we can call it on an object as well.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; fruit.size<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;Small&#8217;<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; orange=fruit('Orange','Round')\r\n&gt;&gt;&gt; orange.size<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&#8216;Small&#8217;<\/div>\n<p>Since we redefined the class, we declared the object again as well.<\/p>\n<p>Likewise, a Python class can contain a function as well.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; class fruit:\r\n           size='Small'\r\n           def __init__(self,color,shape):\r\n                      self.color=color\r\n                      self.shape=shape\r\n           def salutation():\r\n                      print(f\"I am happy\")\r\n\r\n&gt;&gt;&gt; fruit.salutation()<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">I am happy<\/div>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; fruit.salutation<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">&lt;function fruit.salutation at 0x030C8390&gt;<\/div>\n<h3>How to Delete Python Class, Attribute, and Object?<\/h3>\n<p>You can delete an attribute, an object, or a class using the del keyword.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; del orange.shape\r\n&gt;&gt;&gt; orange.shape\r\n<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>Traceback (most recent call last):File &#8220;&lt;pyshell#118&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>orange.shape<\/p>\n<p>AttributeError: &#8216;fruit&#8217; object has no attribute &#8216;shape.&#8217;<\/p>\n<\/div>\n<p>Let\u2019s try deleting an object.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; del orange\r\n&gt;&gt;&gt; orange<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>Traceback (most recent call last):File &#8220;&lt;pyshell#120&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>orange<\/p>\n<p>NameError: name &#8216;orange&#8217; is not defined<\/p>\n<\/div>\n<p>Finally, let\u2019s try deleting the Python class itself.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">&gt;&gt;&gt; fruit\r\n&lt;class '__main__.fruit'&gt;\r\n&gt;&gt;&gt; del fruit\r\n&gt;&gt;&gt; fruit<\/pre>\n<p><strong>Output<\/strong><\/p>\n<div class=\"code-output\">\n<p>Traceback (most recent call last):File &#8220;&lt;pyshell#133&gt;&#8221;, line 1, in &lt;module&gt;<\/p>\n<p>fruit<\/p>\n<p>NameError: name &#8216;fruit&#8217; is not defined<\/p>\n<\/div>\n<p>So, this was all about Python Class and Object Tutorial. Hope you like our explanation.<\/p>\n<h3>Python Interview Questions on Class<\/h3>\n<p>1. What is a class in Python? Explain with an example<\/p>\n<p>2. How do you call a class in Python?<\/p>\n<p>3. Are Python classes slow?<\/p>\n<p>4. When should you use classes in Python?<\/p>\n<p>5. How do you define a class in Python?<\/p>\n<h3>Conclusion<\/h3>\n<p>In this Python Class tutorial, we opened ourselves to Python classes and how to create a class in Python.<\/p>\n<p>We saw how to declare and access attributes and methods in Python. A little too much to take on at once? Get practicing.<\/p>\n<p>Next, we\u2019ll talk about objects in python.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this Python Class tutorial, we are going to explore Python Classes. how they work and how to access. On the other hand, we will discuss what is the Python Object and different attributes&#46;&#46;&#46;<\/p>\n","protected":false},"author":5,"featured_media":36017,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[2539,9193,10415,10731],"class_list":["post-6118","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-classes-in-python","tag-objects-in-python","tag-python-classes","tag-python-objects"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Class - Object &amp; Attributes Belonging to Class in Python - DataFlair<\/title>\n<meta name=\"description\" content=\"Learn what is class in Python with syntax, create and delete class in python, python objects and attributes with 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:\/\/data-flair.training\/blogs\/python-class\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Class - Object &amp; Attributes Belonging to Class in Python - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Learn what is class in Python with syntax, create and delete class in python, python objects and attributes with examples.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-class\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-19T02:21:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-28T05:45:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Classes-in-Python-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Class - Object &amp; Attributes Belonging to Class in Python - DataFlair","description":"Learn what is class in Python with syntax, create and delete class in python, python objects and attributes with 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:\/\/data-flair.training\/blogs\/python-class\/","og_locale":"en_US","og_type":"article","og_title":"Python Class - Object &amp; Attributes Belonging to Class in Python - DataFlair","og_description":"Learn what is class in Python with syntax, create and delete class in python, python objects and attributes with examples.","og_url":"https:\/\/data-flair.training\/blogs\/python-class\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2018-01-19T02:21:33+00:00","article_modified_time":"2026-04-28T05:45:00+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Classes-in-Python-1.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-class\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-class\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823"},"headline":"Python Class &#8211; Object &amp; Attributes Belonging to Class in Python","datePublished":"2018-01-19T02:21:33+00:00","dateModified":"2026-04-28T05:45:00+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-class\/"},"wordCount":1161,"commentCount":13,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-class\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Classes-in-Python-1.jpg","keywords":["classes in python","objects in python","python classes","python objects"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-class\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-class\/","url":"https:\/\/data-flair.training\/blogs\/python-class\/","name":"Python Class - Object &amp; Attributes Belonging to Class in Python - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-class\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-class\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Classes-in-Python-1.jpg","datePublished":"2018-01-19T02:21:33+00:00","dateModified":"2026-04-28T05:45:00+00:00","description":"Learn what is class in Python with syntax, create and delete class in python, python objects and attributes with examples.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-class\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-class\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-class\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Classes-in-Python-1.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2018\/01\/Classes-in-Python-1.jpg","width":1200,"height":628,"caption":"Python Class Tutorial - Python Object &amp; Attributes Belonging to Class"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-class\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Class &#8211; Object &amp; Attributes Belonging to Class in Python"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/7f83c342f5d1632d6f7b4b0b0f447823","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4cf3a74600d131330b8c481d519afd1574093ed89f6d3396a95393ad223eb7cd?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team creates expert-level guides on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our goal is to empower learners with easy-to-understand content. Explore our resources for career growth and practical learning.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam1\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6118","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=6118"}],"version-history":[{"count":19,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6118\/revisions"}],"predecessor-version":[{"id":147979,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/6118\/revisions\/147979"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/36017"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=6118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=6118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=6118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}