[{"data":1,"prerenderedAt":2225},["ShallowReactive",2],{"doc-\u002Fexamples\u002Fpython-basic-class-example-oop":3},{"id":4,"title":5,"body":6,"description":2218,"extension":2219,"meta":2220,"navigation":152,"path":2221,"seo":2222,"stem":2223,"__hash__":2224},"content\u002Fexamples\u002Fpython-basic-class-example-oop.md","Python Basic Class Example (OOP)",{"type":7,"value":8,"toc":2179},"minimark",[9,13,17,20,44,47,52,282,288,308,311,331,335,338,368,376,380,383,480,483,505,508,515,521,524,575,578,609,616,648,661,665,668,695,698,719,722,809,813,827,830,837,841,847,852,911,915,928,931,935,972,976,984,987,991,1010,1017,1021,1024,1030,1043,1048,1051,1057,1082,1085,1091,1096,1113,1119,1122,1128,1170,1175,1181,1187,1213,1221,1224,1238,1242,1245,1252,1255,1292,1295,1334,1340,1344,1346,1360,1362,1388,1391,1399,1401,1415,1417,1432,1438,1442,1444,1464,1466,1485,1492,1496,1498,1555,1557,1614,1621,1625,1628,1648,1651,1936,1940,1973,1976,1980,1983,2003,2006,2009,2081,2084,2098,2102,2106,2109,2116,2121,2125,2128,2132,2135,2139,2169,2175],[10,11,5],"h1",{"id":12},"python-basic-class-example-oop",[14,15,16],"p",{},"This page shows a simple Python class example for beginners.",[14,18,19],{},"You will learn how to:",[21,22,23,27,30,33,36],"ul",{},[24,25,26],"li",{},"Create a class",[24,28,29],{},"Make an object from that class",[24,31,32],{},"Store data in attributes",[24,34,35],{},"Add behavior with a method",[24,37,38,39,43],{},"Use ",[40,41,42],"code",{},"__init__"," to set starting values",[14,45,46],{},"If you are new to classes, this is a good first example because it uses a small real-world idea and keeps the code short.",[48,49,51],"h2",{"id":50},"quick-example","Quick example",[53,54,59],"pre",{"className":55,"code":56,"language":57,"meta":58,"style":58},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","class Dog:\n    def __init__(self, name, age):\n        self.name = name\n        self.age = age\n\n    def bark(self):\n        print(f\"{self.name} says woof!\")\n\nmy_dog = Dog(\"Max\", 3)\nprint(my_dog.name)\nprint(my_dog.age)\nmy_dog.bark()\n","python","",[40,60,61,78,110,132,147,154,169,203,208,237,254,269],{"__ignoreMap":58},[62,63,66,70,74],"span",{"class":64,"line":65},"line",1,[62,67,69],{"class":68},"sbsja","class",[62,71,73],{"class":72},"sbgvK"," Dog",[62,75,77],{"class":76},"sP7_E",":\n",[62,79,81,84,88,91,95,98,102,104,107],{"class":64,"line":80},2,[62,82,83],{"class":68},"    def",[62,85,87],{"class":86},"sptTA"," __init__",[62,89,90],{"class":76},"(",[62,92,94],{"class":93},"smCYv","self",[62,96,97],{"class":76},",",[62,99,101],{"class":100},"sFwrP"," name",[62,103,97],{"class":76},[62,105,106],{"class":100}," age",[62,108,109],{"class":76},"):\n",[62,111,113,117,120,124,128],{"class":64,"line":112},3,[62,114,116],{"class":115},"s_hVV","        self",[62,118,119],{"class":76},".",[62,121,123],{"class":122},"skxfh","name",[62,125,127],{"class":126},"smGrS"," =",[62,129,131],{"class":130},"su5hD"," name\n",[62,133,135,137,139,142,144],{"class":64,"line":134},4,[62,136,116],{"class":115},[62,138,119],{"class":76},[62,140,141],{"class":122},"age",[62,143,127],{"class":126},[62,145,146],{"class":130}," age\n",[62,148,150],{"class":64,"line":149},5,[62,151,153],{"emptyLinePlaceholder":152},true,"\n",[62,155,157,159,163,165,167],{"class":64,"line":156},6,[62,158,83],{"class":68},[62,160,162],{"class":161},"sGLFI"," bark",[62,164,90],{"class":76},[62,166,94],{"class":93},[62,168,109],{"class":76},[62,170,172,175,177,180,184,188,190,192,194,197,200],{"class":64,"line":171},7,[62,173,174],{"class":86},"        print",[62,176,90],{"class":76},[62,178,179],{"class":68},"f",[62,181,183],{"class":182},"s_sjI","\"",[62,185,187],{"class":186},"srdBf","{",[62,189,94],{"class":115},[62,191,119],{"class":76},[62,193,123],{"class":122},[62,195,196],{"class":186},"}",[62,198,199],{"class":182}," says woof!\"",[62,201,202],{"class":76},")\n",[62,204,206],{"class":64,"line":205},8,[62,207,153],{"emptyLinePlaceholder":152},[62,209,211,214,217,220,222,225,228,230,232,235],{"class":64,"line":210},9,[62,212,213],{"class":130},"my_dog ",[62,215,216],{"class":126},"=",[62,218,73],{"class":219},"slqww",[62,221,90],{"class":76},[62,223,183],{"class":224},"sjJ54",[62,226,227],{"class":182},"Max",[62,229,183],{"class":224},[62,231,97],{"class":76},[62,233,234],{"class":186}," 3",[62,236,202],{"class":76},[62,238,240,243,245,248,250,252],{"class":64,"line":239},10,[62,241,242],{"class":86},"print",[62,244,90],{"class":76},[62,246,247],{"class":219},"my_dog",[62,249,119],{"class":76},[62,251,123],{"class":122},[62,253,202],{"class":76},[62,255,257,259,261,263,265,267],{"class":64,"line":256},11,[62,258,242],{"class":86},[62,260,90],{"class":76},[62,262,247],{"class":219},[62,264,119],{"class":76},[62,266,141],{"class":122},[62,268,202],{"class":76},[62,270,272,274,276,279],{"class":64,"line":271},12,[62,273,247],{"class":130},[62,275,119],{"class":76},[62,277,278],{"class":219},"bark",[62,280,281],{"class":76},"()\n",[14,283,284],{},[285,286,287],"strong",{},"Output:",[53,289,291],{"className":55,"code":290,"language":57,"meta":58,"style":58},"Max\n3\nMax says woof!\n",[40,292,293,298,303],{"__ignoreMap":58},[62,294,295],{"class":64,"line":65},[62,296,297],{"class":130},"Max\n",[62,299,300],{"class":64,"line":80},[62,301,302],{"class":186},"3\n",[62,304,305],{"class":64,"line":112},[62,306,307],{"class":130},"Max says woof!\n",[14,309,310],{},"Use this as your first working class example. It shows:",[21,312,313,316,322,325,328],{},[24,314,315],{},"A class",[24,317,318,319,321],{},"An ",[40,320,42],{}," method",[24,323,324],{},"Attributes",[24,326,327],{},"An object",[24,329,330],{},"A method call",[48,332,334],{"id":333},"what-this-example-teaches","What this example teaches",[14,336,337],{},"This example helps you understand these basic OOP ideas:",[21,339,340,346,352,357,363],{},[24,341,342,343,345],{},"A ",[285,344,69],{}," is a template or blueprint",[24,347,318,348,351],{},[285,349,350],{},"object"," is one thing created from that class",[24,353,354,356],{},[285,355,324],{}," store data for the object",[24,358,359,362],{},[285,360,361],{},"Methods"," define what the object can do",[24,364,365,367],{},[40,366,42],{}," sets the starting values when the object is created",[14,369,370,371,119],{},"If you want a fuller beginner explanation, see ",[372,373,375],"a",{"href":374},"\u002Flearn\u002Fpython-classes-and-objects-explained\u002F","Python classes and objects explained",[48,377,379],{"id":378},"the-example-class","The example class",[14,381,382],{},"Here is the full class again before we break it down:",[53,384,386],{"className":55,"code":385,"language":57,"meta":58,"style":58},"class Dog:\n    def __init__(self, name, age):\n        self.name = name\n        self.age = age\n\n    def bark(self):\n        print(f\"{self.name} says woof!\")\n",[40,387,388,396,416,428,440,444,456],{"__ignoreMap":58},[62,389,390,392,394],{"class":64,"line":65},[62,391,69],{"class":68},[62,393,73],{"class":72},[62,395,77],{"class":76},[62,397,398,400,402,404,406,408,410,412,414],{"class":64,"line":80},[62,399,83],{"class":68},[62,401,87],{"class":86},[62,403,90],{"class":76},[62,405,94],{"class":93},[62,407,97],{"class":76},[62,409,101],{"class":100},[62,411,97],{"class":76},[62,413,106],{"class":100},[62,415,109],{"class":76},[62,417,418,420,422,424,426],{"class":64,"line":112},[62,419,116],{"class":115},[62,421,119],{"class":76},[62,423,123],{"class":122},[62,425,127],{"class":126},[62,427,131],{"class":130},[62,429,430,432,434,436,438],{"class":64,"line":134},[62,431,116],{"class":115},[62,433,119],{"class":76},[62,435,141],{"class":122},[62,437,127],{"class":126},[62,439,146],{"class":130},[62,441,442],{"class":64,"line":149},[62,443,153],{"emptyLinePlaceholder":152},[62,445,446,448,450,452,454],{"class":64,"line":156},[62,447,83],{"class":68},[62,449,162],{"class":161},[62,451,90],{"class":76},[62,453,94],{"class":93},[62,455,109],{"class":76},[62,457,458,460,462,464,466,468,470,472,474,476,478],{"class":64,"line":171},[62,459,174],{"class":86},[62,461,90],{"class":76},[62,463,179],{"class":68},[62,465,183],{"class":182},[62,467,187],{"class":186},[62,469,94],{"class":115},[62,471,119],{"class":76},[62,473,123],{"class":122},[62,475,196],{"class":186},[62,477,199],{"class":182},[62,479,202],{"class":76},[14,481,482],{},"This class uses:",[21,484,485,491,499],{},[24,486,487,490],{},[40,488,489],{},"Dog"," as the class name",[24,492,493,495,496,498],{},[40,494,123],{}," and ",[40,497,141],{}," as the two attributes",[24,500,501,504],{},[40,502,503],{},"bark()"," as the one method",[14,506,507],{},"This is a good beginner example because it is small and easy to read.",[48,509,511,512,514],{"id":510},"how-the-__init__-method-works","How the ",[40,513,42],{}," method works",[14,516,517,518,520],{},"The ",[40,519,42],{}," method runs when you create a new object.",[14,522,523],{},"In this example:",[53,525,527],{"className":55,"code":526,"language":57,"meta":58,"style":58},"def __init__(self, name, age):\n    self.name = name\n    self.age = age\n",[40,528,529,550,563],{"__ignoreMap":58},[62,530,531,534,536,538,540,542,544,546,548],{"class":64,"line":65},[62,532,533],{"class":68},"def",[62,535,87],{"class":86},[62,537,90],{"class":76},[62,539,94],{"class":93},[62,541,97],{"class":76},[62,543,101],{"class":100},[62,545,97],{"class":76},[62,547,106],{"class":100},[62,549,109],{"class":76},[62,551,552,555,557,559,561],{"class":64,"line":80},[62,553,554],{"class":115},"    self",[62,556,119],{"class":76},[62,558,123],{"class":122},[62,560,127],{"class":126},[62,562,131],{"class":130},[62,564,565,567,569,571,573],{"class":64,"line":112},[62,566,554],{"class":115},[62,568,119],{"class":76},[62,570,141],{"class":122},[62,572,127],{"class":126},[62,574,146],{"class":130},[14,576,577],{},"Here is what each part means:",[21,579,580,585,590,597,603],{},[24,581,582,584],{},[40,583,42],{}," is the special method Python uses to set up a new object",[24,586,587,589],{},[40,588,94],{}," refers to the current object",[24,591,592,495,594,596],{},[40,593,123],{},[40,595,141],{}," are values passed in when the object is created",[24,598,599,602],{},[40,600,601],{},"self.name = name"," stores the value in the object",[24,604,605,608],{},[40,606,607],{},"self.age = age"," stores the age in the object",[14,610,611,612,615],{},"So if you create ",[40,613,614],{},"Dog(\"Max\", 3)",", Python does this setup:",[21,617,618,626,633,641],{},[24,619,620,622,623],{},[40,621,123],{}," becomes ",[40,624,625],{},"\"Max\"",[24,627,628,622,630],{},[40,629,141],{},[40,631,632],{},"3",[24,634,635,638,639],{},[40,636,637],{},"self.name"," is set to ",[40,640,625],{},[24,642,643,638,646],{},[40,644,645],{},"self.age",[40,647,632],{},[14,649,650,651,653,654,119],{},"If ",[40,652,94],{}," feels confusing, see ",[372,655,657,658,660],{"href":656},"\u002Flearn\u002Fthe-__init__-method-in-python-explained\u002F","the ",[40,659,42],{}," method in Python explained",[48,662,664],{"id":663},"how-to-create-an-object","How to create an object",[14,666,667],{},"You create an object by calling the class name like a function:",[53,669,671],{"className":55,"code":670,"language":57,"meta":58,"style":58},"my_dog = Dog(\"Max\", 3)\n",[40,672,673],{"__ignoreMap":58},[62,674,675,677,679,681,683,685,687,689,691,693],{"class":64,"line":65},[62,676,213],{"class":130},[62,678,216],{"class":126},[62,680,73],{"class":219},[62,682,90],{"class":76},[62,684,183],{"class":224},[62,686,227],{"class":182},[62,688,183],{"class":224},[62,690,97],{"class":76},[62,692,234],{"class":186},[62,694,202],{"class":76},[14,696,697],{},"This means:",[21,699,700,705,710],{},[24,701,702,704],{},[40,703,489],{}," is the class",[24,706,707,709],{},[40,708,247],{}," is the object",[24,711,712,495,714,716,717],{},[40,713,625],{},[40,715,632],{}," are passed into ",[40,718,42],{},[14,720,721],{},"You can create more than one object from the same class:",[53,723,725],{"className":55,"code":724,"language":57,"meta":58,"style":58},"dog1 = Dog(\"Max\", 3)\ndog2 = Dog(\"Bella\", 5)\n\nprint(dog1.name)\nprint(dog2.name)\n",[40,726,727,750,775,779,794],{"__ignoreMap":58},[62,728,729,732,734,736,738,740,742,744,746,748],{"class":64,"line":65},[62,730,731],{"class":130},"dog1 ",[62,733,216],{"class":126},[62,735,73],{"class":219},[62,737,90],{"class":76},[62,739,183],{"class":224},[62,741,227],{"class":182},[62,743,183],{"class":224},[62,745,97],{"class":76},[62,747,234],{"class":186},[62,749,202],{"class":76},[62,751,752,755,757,759,761,763,766,768,770,773],{"class":64,"line":80},[62,753,754],{"class":130},"dog2 ",[62,756,216],{"class":126},[62,758,73],{"class":219},[62,760,90],{"class":76},[62,762,183],{"class":224},[62,764,765],{"class":182},"Bella",[62,767,183],{"class":224},[62,769,97],{"class":76},[62,771,772],{"class":186}," 5",[62,774,202],{"class":76},[62,776,777],{"class":64,"line":112},[62,778,153],{"emptyLinePlaceholder":152},[62,780,781,783,785,788,790,792],{"class":64,"line":134},[62,782,242],{"class":86},[62,784,90],{"class":76},[62,786,787],{"class":219},"dog1",[62,789,119],{"class":76},[62,791,123],{"class":122},[62,793,202],{"class":76},[62,795,796,798,800,803,805,807],{"class":64,"line":149},[62,797,242],{"class":86},[62,799,90],{"class":76},[62,801,802],{"class":219},"dog2",[62,804,119],{"class":76},[62,806,123],{"class":122},[62,808,202],{"class":76},[14,810,811],{},[285,812,287],{},[53,814,816],{"className":55,"code":815,"language":57,"meta":58,"style":58},"Max\nBella\n",[40,817,818,822],{"__ignoreMap":58},[62,819,820],{"class":64,"line":65},[62,821,297],{"class":130},[62,823,824],{"class":64,"line":80},[62,825,826],{"class":130},"Bella\n",[14,828,829],{},"Both objects use the same class, but each object can store different values.",[14,831,832,833,119],{},"You can learn more in ",[372,834,836],{"href":835},"\u002Fhow-to\u002Fhow-to-create-an-object-in-python\u002F","how to create an object in Python",[48,838,840],{"id":839},"how-to-access-attributes-and-call-methods","How to access attributes and call methods",[14,842,38,843,846],{},[285,844,845],{},"dot notation"," to work with object data and behavior.",[848,849,851],"h3",{"id":850},"read-attributes","Read attributes",[53,853,855],{"className":55,"code":854,"language":57,"meta":58,"style":58},"my_dog = Dog(\"Max\", 3)\n\nprint(my_dog.name)\nprint(my_dog.age)\n",[40,856,857,879,883,897],{"__ignoreMap":58},[62,858,859,861,863,865,867,869,871,873,875,877],{"class":64,"line":65},[62,860,213],{"class":130},[62,862,216],{"class":126},[62,864,73],{"class":219},[62,866,90],{"class":76},[62,868,183],{"class":224},[62,870,227],{"class":182},[62,872,183],{"class":224},[62,874,97],{"class":76},[62,876,234],{"class":186},[62,878,202],{"class":76},[62,880,881],{"class":64,"line":80},[62,882,153],{"emptyLinePlaceholder":152},[62,884,885,887,889,891,893,895],{"class":64,"line":112},[62,886,242],{"class":86},[62,888,90],{"class":76},[62,890,247],{"class":219},[62,892,119],{"class":76},[62,894,123],{"class":122},[62,896,202],{"class":76},[62,898,899,901,903,905,907,909],{"class":64,"line":134},[62,900,242],{"class":86},[62,902,90],{"class":76},[62,904,247],{"class":219},[62,906,119],{"class":76},[62,908,141],{"class":122},[62,910,202],{"class":76},[14,912,913],{},[285,914,287],{},[53,916,918],{"className":55,"code":917,"language":57,"meta":58,"style":58},"Max\n3\n",[40,919,920,924],{"__ignoreMap":58},[62,921,922],{"class":64,"line":65},[62,923,297],{"class":130},[62,925,926],{"class":64,"line":80},[62,927,302],{"class":186},[14,929,930],{},"This reads stored data from the object.",[848,932,934],{"id":933},"call-a-method","Call a method",[53,936,938],{"className":55,"code":937,"language":57,"meta":58,"style":58},"my_dog = Dog(\"Max\", 3)\nmy_dog.bark()\n",[40,939,940,962],{"__ignoreMap":58},[62,941,942,944,946,948,950,952,954,956,958,960],{"class":64,"line":65},[62,943,213],{"class":130},[62,945,216],{"class":126},[62,947,73],{"class":219},[62,949,90],{"class":76},[62,951,183],{"class":224},[62,953,227],{"class":182},[62,955,183],{"class":224},[62,957,97],{"class":76},[62,959,234],{"class":186},[62,961,202],{"class":76},[62,963,964,966,968,970],{"class":64,"line":80},[62,965,247],{"class":130},[62,967,119],{"class":76},[62,969,278],{"class":219},[62,971,281],{"class":76},[14,973,974],{},[285,975,287],{},[53,977,978],{"className":55,"code":307,"language":57,"meta":58,"style":58},[40,979,980],{"__ignoreMap":58},[62,981,982],{"class":64,"line":65},[62,983,307],{"class":130},[14,985,986],{},"This runs behavior defined in the class.",[848,988,990],{"id":989},"data-vs-behavior","Data vs behavior",[21,992,993,999,1004],{},[24,994,995,998],{},[40,996,997],{},"my_dog.name"," reads data",[24,1000,1001,998],{},[40,1002,1003],{},"my_dog.age",[24,1005,1006,1009],{},[40,1007,1008],{},"my_dog.bark()"," runs a method",[14,1011,1012,1013,119],{},"If you want more method examples, see ",[372,1014,1016],{"href":1015},"\u002Flearn\u002Fbasic-methods-in-python-classes-explained\u002F","basic methods in Python classes explained",[48,1018,1020],{"id":1019},"step-by-step-code-breakdown","Step-by-step code breakdown",[14,1022,1023],{},"Let’s go through the main lines one by one.",[848,1025,1027],{"id":1026},"class-dog",[40,1028,1029],{},"class Dog:",[53,1031,1033],{"className":55,"code":1032,"language":57,"meta":58,"style":58},"class Dog:\n",[40,1034,1035],{"__ignoreMap":58},[62,1036,1037,1039,1041],{"class":64,"line":65},[62,1038,69],{"class":68},[62,1040,73],{"class":72},[62,1042,77],{"class":76},[14,1044,1045,1046,119],{},"This creates a new class named ",[40,1047,489],{},[14,1049,1050],{},"Think of it as a blueprint for making dog objects.",[848,1052,1054],{"id":1053},"def-__init__self-name-age",[40,1055,1056],{},"def __init__(self, name, age):",[53,1058,1060],{"className":55,"code":1059,"language":57,"meta":58,"style":58},"def __init__(self, name, age):\n",[40,1061,1062],{"__ignoreMap":58},[62,1063,1064,1066,1068,1070,1072,1074,1076,1078,1080],{"class":64,"line":65},[62,1065,533],{"class":68},[62,1067,87],{"class":86},[62,1069,90],{"class":76},[62,1071,94],{"class":93},[62,1073,97],{"class":76},[62,1075,101],{"class":100},[62,1077,97],{"class":76},[62,1079,106],{"class":100},[62,1081,109],{"class":76},[14,1083,1084],{},"This defines the setup method for new objects.",[14,1086,1087,1088,1090],{},"When you create a ",[40,1089,489],{},", Python runs this method automatically.",[848,1092,1094],{"id":1093},"selfname-name",[40,1095,601],{},[53,1097,1099],{"className":55,"code":1098,"language":57,"meta":58,"style":58},"self.name = name\n",[40,1100,1101],{"__ignoreMap":58},[62,1102,1103,1105,1107,1109,1111],{"class":64,"line":65},[62,1104,94],{"class":115},[62,1106,119],{"class":76},[62,1108,123],{"class":122},[62,1110,127],{"class":126},[62,1112,131],{"class":130},[14,1114,1115,1116,1118],{},"This creates an attribute named ",[40,1117,123],{}," on the object.",[14,1120,1121],{},"The value passed in becomes part of that object.",[848,1123,1125],{"id":1124},"def-barkself",[40,1126,1127],{},"def bark(self):",[53,1129,1131],{"className":55,"code":1130,"language":57,"meta":58,"style":58},"def bark(self):\n    print(f\"{self.name} says woof!\")\n",[40,1132,1133,1145],{"__ignoreMap":58},[62,1134,1135,1137,1139,1141,1143],{"class":64,"line":65},[62,1136,533],{"class":68},[62,1138,162],{"class":161},[62,1140,90],{"class":76},[62,1142,94],{"class":93},[62,1144,109],{"class":76},[62,1146,1147,1150,1152,1154,1156,1158,1160,1162,1164,1166,1168],{"class":64,"line":80},[62,1148,1149],{"class":86},"    print",[62,1151,90],{"class":76},[62,1153,179],{"class":68},[62,1155,183],{"class":182},[62,1157,187],{"class":186},[62,1159,94],{"class":115},[62,1161,119],{"class":76},[62,1163,123],{"class":122},[62,1165,196],{"class":186},[62,1167,199],{"class":182},[62,1169,202],{"class":76},[14,1171,1172,1173,119],{},"This defines a method named ",[40,1174,278],{},[14,1176,1177,1178,1180],{},"It uses ",[40,1179,637],{}," so the message matches the current object.",[848,1182,1184],{"id":1183},"my_dog-dogmax-3",[40,1185,1186],{},"my_dog = Dog(\"Max\", 3)",[53,1188,1189],{"className":55,"code":670,"language":57,"meta":58,"style":58},[40,1190,1191],{"__ignoreMap":58},[62,1192,1193,1195,1197,1199,1201,1203,1205,1207,1209,1211],{"class":64,"line":65},[62,1194,213],{"class":130},[62,1196,216],{"class":126},[62,1198,73],{"class":219},[62,1200,90],{"class":76},[62,1202,183],{"class":224},[62,1204,227],{"class":182},[62,1206,183],{"class":224},[62,1208,97],{"class":76},[62,1210,234],{"class":186},[62,1212,202],{"class":76},[14,1214,1215,1216,1218,1219,119],{},"This creates one ",[40,1217,489],{}," object and stores it in the variable ",[40,1220,247],{},[14,1222,1223],{},"At that moment:",[21,1225,1226,1232],{},[24,1227,1228,622,1230],{},[40,1229,637],{},[40,1231,625],{},[24,1233,1234,622,1236],{},[40,1235,645],{},[40,1237,632],{},[48,1239,1241],{"id":1240},"common-beginner-mistakes","Common beginner mistakes",[14,1243,1244],{},"Here are some common problems beginners run into with classes.",[848,1246,1248,1249,1251],{"id":1247},"forgetting-self-in-method-definitions","Forgetting ",[40,1250,94],{}," in method definitions",[14,1253,1254],{},"Wrong:",[53,1256,1258],{"className":55,"code":1257,"language":57,"meta":58,"style":58},"class Dog:\n    def bark():\n        print(\"Woof!\")\n",[40,1259,1260,1268,1277],{"__ignoreMap":58},[62,1261,1262,1264,1266],{"class":64,"line":65},[62,1263,69],{"class":68},[62,1265,73],{"class":72},[62,1267,77],{"class":76},[62,1269,1270,1272,1274],{"class":64,"line":80},[62,1271,83],{"class":68},[62,1273,162],{"class":161},[62,1275,1276],{"class":76},"():\n",[62,1278,1279,1281,1283,1285,1288,1290],{"class":64,"line":112},[62,1280,174],{"class":86},[62,1282,90],{"class":76},[62,1284,183],{"class":224},[62,1286,1287],{"class":182},"Woof!",[62,1289,183],{"class":224},[62,1291,202],{"class":76},[14,1293,1294],{},"Right:",[53,1296,1298],{"className":55,"code":1297,"language":57,"meta":58,"style":58},"class Dog:\n    def bark(self):\n        print(\"Woof!\")\n",[40,1299,1300,1308,1320],{"__ignoreMap":58},[62,1301,1302,1304,1306],{"class":64,"line":65},[62,1303,69],{"class":68},[62,1305,73],{"class":72},[62,1307,77],{"class":76},[62,1309,1310,1312,1314,1316,1318],{"class":64,"line":80},[62,1311,83],{"class":68},[62,1313,162],{"class":161},[62,1315,90],{"class":76},[62,1317,94],{"class":93},[62,1319,109],{"class":76},[62,1321,1322,1324,1326,1328,1330,1332],{"class":64,"line":112},[62,1323,174],{"class":86},[62,1325,90],{"class":76},[62,1327,183],{"class":224},[62,1329,1287],{"class":182},[62,1331,183],{"class":224},[62,1333,202],{"class":76},[14,1335,1336,1337,1339],{},"Inside a class, instance methods need ",[40,1338,94],{}," as the first parameter.",[848,1341,1343],{"id":1342},"forgetting-parentheses-when-creating-an-object","Forgetting parentheses when creating an object",[14,1345,1254],{},[53,1347,1349],{"className":55,"code":1348,"language":57,"meta":58,"style":58},"my_dog = Dog\n",[40,1350,1351],{"__ignoreMap":58},[62,1352,1353,1355,1357],{"class":64,"line":65},[62,1354,213],{"class":130},[62,1356,216],{"class":126},[62,1358,1359],{"class":130}," Dog\n",[14,1361,1294],{},[53,1363,1364],{"className":55,"code":670,"language":57,"meta":58,"style":58},[40,1365,1366],{"__ignoreMap":58},[62,1367,1368,1370,1372,1374,1376,1378,1380,1382,1384,1386],{"class":64,"line":65},[62,1369,213],{"class":130},[62,1371,216],{"class":126},[62,1373,73],{"class":219},[62,1375,90],{"class":76},[62,1377,183],{"class":224},[62,1379,227],{"class":182},[62,1381,183],{"class":224},[62,1383,97],{"class":76},[62,1385,234],{"class":186},[62,1387,202],{"class":76},[14,1389,1390],{},"Without parentheses, you are referring to the class itself, not creating an object.",[848,1392,1394,1395,1398],{"id":1393},"using-a-method-name-without-when-trying-to-call-it","Using a method name without ",[40,1396,1397],{},"()"," when trying to call it",[14,1400,1254],{},[53,1402,1404],{"className":55,"code":1403,"language":57,"meta":58,"style":58},"my_dog.bark\n",[40,1405,1406],{"__ignoreMap":58},[62,1407,1408,1410,1412],{"class":64,"line":65},[62,1409,247],{"class":130},[62,1411,119],{"class":76},[62,1413,1414],{"class":122},"bark\n",[14,1416,1294],{},[53,1418,1420],{"className":55,"code":1419,"language":57,"meta":58,"style":58},"my_dog.bark()\n",[40,1421,1422],{"__ignoreMap":58},[62,1423,1424,1426,1428,1430],{"class":64,"line":65},[62,1425,247],{"class":130},[62,1427,119],{"class":76},[62,1429,278],{"class":219},[62,1431,281],{"class":76},[14,1433,1434,1435,1437],{},"Without ",[40,1436,1397],{},", Python gives you the method itself instead of running it.",[848,1439,1441],{"id":1440},"misspelling-attribute-names","Misspelling attribute names",[14,1443,1254],{},[53,1445,1447],{"className":55,"code":1446,"language":57,"meta":58,"style":58},"print(my_dog.nam)\n",[40,1448,1449],{"__ignoreMap":58},[62,1450,1451,1453,1455,1457,1459,1462],{"class":64,"line":65},[62,1452,242],{"class":86},[62,1454,90],{"class":76},[62,1456,247],{"class":219},[62,1458,119],{"class":76},[62,1460,1461],{"class":122},"nam",[62,1463,202],{"class":76},[14,1465,1294],{},[53,1467,1469],{"className":55,"code":1468,"language":57,"meta":58,"style":58},"print(my_dog.name)\n",[40,1470,1471],{"__ignoreMap":58},[62,1472,1473,1475,1477,1479,1481,1483],{"class":64,"line":65},[62,1474,242],{"class":86},[62,1476,90],{"class":76},[62,1478,247],{"class":219},[62,1480,119],{"class":76},[62,1482,123],{"class":122},[62,1484,202],{"class":76},[14,1486,1487,1488,119],{},"A misspelled attribute name can cause an ",[372,1489,1491],{"href":1490},"\u002Ferrors\u002Fattributeerror-object-has-no-attribute-fix\u002F","AttributeError: object has no attribute",[848,1493,1495],{"id":1494},"bad-indentation-inside-the-class","Bad indentation inside the class",[14,1497,1254],{},[53,1499,1501],{"className":55,"code":1500,"language":57,"meta":58,"style":58},"class Dog:\ndef __init__(self, name, age):\n    self.name = name\n    self.age = age\n",[40,1502,1503,1511,1531,1543],{"__ignoreMap":58},[62,1504,1505,1507,1509],{"class":64,"line":65},[62,1506,69],{"class":68},[62,1508,73],{"class":72},[62,1510,77],{"class":76},[62,1512,1513,1515,1517,1519,1521,1523,1525,1527,1529],{"class":64,"line":80},[62,1514,533],{"class":68},[62,1516,87],{"class":86},[62,1518,90],{"class":76},[62,1520,94],{"class":93},[62,1522,97],{"class":76},[62,1524,101],{"class":100},[62,1526,97],{"class":76},[62,1528,106],{"class":100},[62,1530,109],{"class":76},[62,1532,1533,1535,1537,1539,1541],{"class":64,"line":112},[62,1534,554],{"class":115},[62,1536,119],{"class":76},[62,1538,123],{"class":122},[62,1540,127],{"class":126},[62,1542,131],{"class":130},[62,1544,1545,1547,1549,1551,1553],{"class":64,"line":134},[62,1546,554],{"class":115},[62,1548,119],{"class":76},[62,1550,141],{"class":122},[62,1552,127],{"class":126},[62,1554,146],{"class":130},[14,1556,1294],{},[53,1558,1560],{"className":55,"code":1559,"language":57,"meta":58,"style":58},"class Dog:\n    def __init__(self, name, age):\n        self.name = name\n        self.age = age\n",[40,1561,1562,1570,1590,1602],{"__ignoreMap":58},[62,1563,1564,1566,1568],{"class":64,"line":65},[62,1565,69],{"class":68},[62,1567,73],{"class":72},[62,1569,77],{"class":76},[62,1571,1572,1574,1576,1578,1580,1582,1584,1586,1588],{"class":64,"line":80},[62,1573,83],{"class":68},[62,1575,87],{"class":86},[62,1577,90],{"class":76},[62,1579,94],{"class":93},[62,1581,97],{"class":76},[62,1583,101],{"class":100},[62,1585,97],{"class":76},[62,1587,106],{"class":100},[62,1589,109],{"class":76},[62,1591,1592,1594,1596,1598,1600],{"class":64,"line":112},[62,1593,116],{"class":115},[62,1595,119],{"class":76},[62,1597,123],{"class":122},[62,1599,127],{"class":126},[62,1601,131],{"class":130},[62,1603,1604,1606,1608,1610,1612],{"class":64,"line":134},[62,1605,116],{"class":115},[62,1607,119],{"class":76},[62,1609,141],{"class":122},[62,1611,127],{"class":126},[62,1613,146],{"class":130},[14,1615,1616,1617,119],{},"Python uses indentation to understand code blocks. Bad indentation can cause an ",[372,1618,1620],{"href":1619},"\u002Ferrors\u002Findentationerror-expected-an-indented-block-fix\u002F","IndentationError: expected an indented block",[48,1622,1624],{"id":1623},"try-it-yourself","Try it yourself",[14,1626,1627],{},"Once the basic example works, try these small changes:",[21,1629,1630,1633,1639,1642],{},[24,1631,1632],{},"Change the object values",[24,1634,1635,1636,1638],{},"Create a second ",[40,1637,489],{}," object",[24,1640,1641],{},"Print both objects' data",[24,1643,1644,1645],{},"Add another method such as ",[40,1646,1647],{},"birthday()",[14,1649,1650],{},"Example:",[53,1652,1654],{"className":55,"code":1653,"language":57,"meta":58,"style":58},"class Dog:\n    def __init__(self, name, age):\n        self.name = name\n        self.age = age\n\n    def bark(self):\n        print(f\"{self.name} says woof!\")\n\n    def birthday(self):\n        self.age += 1\n        print(f\"{self.name} is now {self.age}\")\n\ndog1 = Dog(\"Max\", 3)\ndog2 = Dog(\"Bella\", 5)\n\nprint(dog1.name, dog1.age)\nprint(dog2.name, dog2.age)\n\ndog1.birthday()\n",[40,1655,1656,1664,1684,1696,1708,1712,1724,1748,1752,1765,1779,1816,1820,1843,1866,1871,1895,1919,1924],{"__ignoreMap":58},[62,1657,1658,1660,1662],{"class":64,"line":65},[62,1659,69],{"class":68},[62,1661,73],{"class":72},[62,1663,77],{"class":76},[62,1665,1666,1668,1670,1672,1674,1676,1678,1680,1682],{"class":64,"line":80},[62,1667,83],{"class":68},[62,1669,87],{"class":86},[62,1671,90],{"class":76},[62,1673,94],{"class":93},[62,1675,97],{"class":76},[62,1677,101],{"class":100},[62,1679,97],{"class":76},[62,1681,106],{"class":100},[62,1683,109],{"class":76},[62,1685,1686,1688,1690,1692,1694],{"class":64,"line":112},[62,1687,116],{"class":115},[62,1689,119],{"class":76},[62,1691,123],{"class":122},[62,1693,127],{"class":126},[62,1695,131],{"class":130},[62,1697,1698,1700,1702,1704,1706],{"class":64,"line":134},[62,1699,116],{"class":115},[62,1701,119],{"class":76},[62,1703,141],{"class":122},[62,1705,127],{"class":126},[62,1707,146],{"class":130},[62,1709,1710],{"class":64,"line":149},[62,1711,153],{"emptyLinePlaceholder":152},[62,1713,1714,1716,1718,1720,1722],{"class":64,"line":156},[62,1715,83],{"class":68},[62,1717,162],{"class":161},[62,1719,90],{"class":76},[62,1721,94],{"class":93},[62,1723,109],{"class":76},[62,1725,1726,1728,1730,1732,1734,1736,1738,1740,1742,1744,1746],{"class":64,"line":171},[62,1727,174],{"class":86},[62,1729,90],{"class":76},[62,1731,179],{"class":68},[62,1733,183],{"class":182},[62,1735,187],{"class":186},[62,1737,94],{"class":115},[62,1739,119],{"class":76},[62,1741,123],{"class":122},[62,1743,196],{"class":186},[62,1745,199],{"class":182},[62,1747,202],{"class":76},[62,1749,1750],{"class":64,"line":205},[62,1751,153],{"emptyLinePlaceholder":152},[62,1753,1754,1756,1759,1761,1763],{"class":64,"line":210},[62,1755,83],{"class":68},[62,1757,1758],{"class":161}," birthday",[62,1760,90],{"class":76},[62,1762,94],{"class":93},[62,1764,109],{"class":76},[62,1766,1767,1769,1771,1773,1776],{"class":64,"line":239},[62,1768,116],{"class":115},[62,1770,119],{"class":76},[62,1772,141],{"class":122},[62,1774,1775],{"class":126}," +=",[62,1777,1778],{"class":186}," 1\n",[62,1780,1781,1783,1785,1787,1789,1791,1793,1795,1797,1799,1802,1804,1806,1808,1810,1812,1814],{"class":64,"line":256},[62,1782,174],{"class":86},[62,1784,90],{"class":76},[62,1786,179],{"class":68},[62,1788,183],{"class":182},[62,1790,187],{"class":186},[62,1792,94],{"class":115},[62,1794,119],{"class":76},[62,1796,123],{"class":122},[62,1798,196],{"class":186},[62,1800,1801],{"class":182}," is now ",[62,1803,187],{"class":186},[62,1805,94],{"class":115},[62,1807,119],{"class":76},[62,1809,141],{"class":122},[62,1811,196],{"class":186},[62,1813,183],{"class":182},[62,1815,202],{"class":76},[62,1817,1818],{"class":64,"line":271},[62,1819,153],{"emptyLinePlaceholder":152},[62,1821,1823,1825,1827,1829,1831,1833,1835,1837,1839,1841],{"class":64,"line":1822},13,[62,1824,731],{"class":130},[62,1826,216],{"class":126},[62,1828,73],{"class":219},[62,1830,90],{"class":76},[62,1832,183],{"class":224},[62,1834,227],{"class":182},[62,1836,183],{"class":224},[62,1838,97],{"class":76},[62,1840,234],{"class":186},[62,1842,202],{"class":76},[62,1844,1846,1848,1850,1852,1854,1856,1858,1860,1862,1864],{"class":64,"line":1845},14,[62,1847,754],{"class":130},[62,1849,216],{"class":126},[62,1851,73],{"class":219},[62,1853,90],{"class":76},[62,1855,183],{"class":224},[62,1857,765],{"class":182},[62,1859,183],{"class":224},[62,1861,97],{"class":76},[62,1863,772],{"class":186},[62,1865,202],{"class":76},[62,1867,1869],{"class":64,"line":1868},15,[62,1870,153],{"emptyLinePlaceholder":152},[62,1872,1874,1876,1878,1880,1882,1884,1886,1889,1891,1893],{"class":64,"line":1873},16,[62,1875,242],{"class":86},[62,1877,90],{"class":76},[62,1879,787],{"class":219},[62,1881,119],{"class":76},[62,1883,123],{"class":122},[62,1885,97],{"class":76},[62,1887,1888],{"class":219}," dog1",[62,1890,119],{"class":76},[62,1892,141],{"class":122},[62,1894,202],{"class":76},[62,1896,1898,1900,1902,1904,1906,1908,1910,1913,1915,1917],{"class":64,"line":1897},17,[62,1899,242],{"class":86},[62,1901,90],{"class":76},[62,1903,802],{"class":219},[62,1905,119],{"class":76},[62,1907,123],{"class":122},[62,1909,97],{"class":76},[62,1911,1912],{"class":219}," dog2",[62,1914,119],{"class":76},[62,1916,141],{"class":122},[62,1918,202],{"class":76},[62,1920,1922],{"class":64,"line":1921},18,[62,1923,153],{"emptyLinePlaceholder":152},[62,1925,1927,1929,1931,1934],{"class":64,"line":1926},19,[62,1928,787],{"class":130},[62,1930,119],{"class":76},[62,1932,1933],{"class":219},"birthday",[62,1935,281],{"class":76},[14,1937,1938],{},[285,1939,287],{},[53,1941,1943],{"className":55,"code":1942,"language":57,"meta":58,"style":58},"Max 3\nBella 5\nMax is now 4\n",[40,1944,1945,1952,1960],{"__ignoreMap":58},[62,1946,1947,1950],{"class":64,"line":65},[62,1948,1949],{"class":130},"Max ",[62,1951,302],{"class":186},[62,1953,1954,1957],{"class":64,"line":80},[62,1955,1956],{"class":130},"Bella ",[62,1958,1959],{"class":186},"5\n",[62,1961,1962,1964,1967,1970],{"class":64,"line":112},[62,1963,1949],{"class":130},[62,1965,1966],{"class":126},"is",[62,1968,1969],{"class":130}," now ",[62,1971,1972],{"class":186},"4\n",[14,1974,1975],{},"This is a good next step after learning the basic example.",[48,1977,1979],{"id":1978},"common-causes-of-confusion","Common causes of confusion",[14,1981,1982],{},"Beginners often get stuck on these points:",[21,1984,1985,1988,1994,1997,2000],{},[24,1986,1987],{},"Confusing a class with an object",[24,1989,1990,1991,1993],{},"Not understanding what ",[40,1992,94],{}," refers to",[24,1995,1996],{},"Mixing up attributes and methods",[24,1998,1999],{},"Indentation mistakes inside the class body",[24,2001,2002],{},"Calling methods with missing required arguments",[14,2004,2005],{},"If that happens, test one small part at a time and print values often.",[14,2007,2008],{},"Useful debugging checks:",[53,2010,2012],{"className":55,"code":2011,"language":57,"meta":58,"style":58},"print(type(my_dog))\nprint(my_dog.name)\nprint(my_dog.age)\ndir(my_dog)\nhelp(Dog)\n",[40,2013,2014,2031,2045,2059,2070],{"__ignoreMap":58},[62,2015,2016,2018,2020,2024,2026,2028],{"class":64,"line":65},[62,2017,242],{"class":86},[62,2019,90],{"class":76},[62,2021,2023],{"class":2022},"sZMiF","type",[62,2025,90],{"class":76},[62,2027,247],{"class":219},[62,2029,2030],{"class":76},"))\n",[62,2032,2033,2035,2037,2039,2041,2043],{"class":64,"line":80},[62,2034,242],{"class":86},[62,2036,90],{"class":76},[62,2038,247],{"class":219},[62,2040,119],{"class":76},[62,2042,123],{"class":122},[62,2044,202],{"class":76},[62,2046,2047,2049,2051,2053,2055,2057],{"class":64,"line":112},[62,2048,242],{"class":86},[62,2050,90],{"class":76},[62,2052,247],{"class":219},[62,2054,119],{"class":76},[62,2056,141],{"class":122},[62,2058,202],{"class":76},[62,2060,2061,2064,2066,2068],{"class":64,"line":134},[62,2062,2063],{"class":86},"dir",[62,2065,90],{"class":76},[62,2067,247],{"class":219},[62,2069,202],{"class":76},[62,2071,2072,2075,2077,2079],{"class":64,"line":149},[62,2073,2074],{"class":86},"help",[62,2076,90],{"class":76},[62,2078,489],{"class":219},[62,2080,202],{"class":76},[14,2082,2083],{},"These can help you see:",[21,2085,2086,2092,2095],{},[24,2087,2088,2089,2091],{},"What type ",[40,2090,247],{}," is",[24,2093,2094],{},"Whether attributes exist",[24,2096,2097],{},"What names and methods are available on the object",[48,2099,2101],{"id":2100},"faq","FAQ",[848,2103,2105],{"id":2104},"what-is-the-difference-between-a-class-and-an-object","What is the difference between a class and an object?",[14,2107,2108],{},"A class is a blueprint. An object is one created item based on that blueprint.",[848,2110,2112,2113,2115],{"id":2111},"why-do-i-need-self-in-a-class","Why do I need ",[40,2114,94],{}," in a class?",[14,2117,2118,2120],{},[40,2119,94],{}," lets Python refer to the current object so each object can store its own data.",[848,2122,2124],{"id":2123},"is-this-page-teaching-all-of-oop","Is this page teaching all of OOP?",[14,2126,2127],{},"No. This page focuses on one simple class example. Broader OOP concepts belong on separate learn pages.",[848,2129,2131],{"id":2130},"can-a-class-have-more-than-one-method","Can a class have more than one method?",[14,2133,2134],{},"Yes. A class can have many methods, but this example stays small to make the core idea clear.",[48,2136,2138],{"id":2137},"see-also","See also",[21,2140,2141,2145,2151,2157,2163],{},[24,2142,2143],{},[372,2144,375],{"href":374},[24,2146,2147],{},[372,2148,2150],{"href":2149},"\u002Flearn\u002Fobject-oriented-programming-in-python-explained\u002F","Object-oriented programming in Python explained",[24,2152,2153],{},[372,2154,517,2155,660],{"href":656},[40,2156,42],{},[24,2158,2159],{},[372,2160,2162],{"href":2161},"\u002Fhow-to\u002Fhow-to-create-a-class-in-python\u002F","How to create a class in Python",[24,2164,2165],{},[372,2166,2168],{"href":2167},"\u002Fhow-to\u002Fhow-to-add-methods-to-a-class-in-python\u002F","How to add methods to a class in Python",[14,2170,2171,2172,2174],{},"After you understand this example, the next good step is to create your own class and then learn ",[40,2173,42],{}," and methods in more detail.",[2176,2177,2178],"style",{},"html pre.shiki code .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sbgvK, html code.shiki .sbgvK{--shiki-light:#E2931D;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .smCYv, html code.shiki .smCYv{--shiki-light:#E53935;--shiki-light-font-style:italic;--shiki-default:#24292E;--shiki-default-font-style:inherit;--shiki-dark:#E1E4E8;--shiki-dark-font-style:inherit}html pre.shiki code .sFwrP, html code.shiki .sFwrP{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#24292E;--shiki-default-font-style:inherit;--shiki-dark:#E1E4E8;--shiki-dark-font-style:inherit}html pre.shiki code .s_hVV, html code.shiki .s_hVV{--shiki-light:#90A4AE;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sGLFI, html code.shiki .sGLFI{--shiki-light:#6182B8;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":58,"searchDepth":80,"depth":80,"links":2180},[2181,2182,2183,2184,2186,2187,2192,2199,2208,2209,2210,2217],{"id":50,"depth":80,"text":51},{"id":333,"depth":80,"text":334},{"id":378,"depth":80,"text":379},{"id":510,"depth":80,"text":2185},"How the __init__ method works",{"id":663,"depth":80,"text":664},{"id":839,"depth":80,"text":840,"children":2188},[2189,2190,2191],{"id":850,"depth":112,"text":851},{"id":933,"depth":112,"text":934},{"id":989,"depth":112,"text":990},{"id":1019,"depth":80,"text":1020,"children":2193},[2194,2195,2196,2197,2198],{"id":1026,"depth":112,"text":1029},{"id":1053,"depth":112,"text":1056},{"id":1093,"depth":112,"text":601},{"id":1124,"depth":112,"text":1127},{"id":1183,"depth":112,"text":1186},{"id":1240,"depth":80,"text":1241,"children":2200},[2201,2203,2204,2206,2207],{"id":1247,"depth":112,"text":2202},"Forgetting self in method definitions",{"id":1342,"depth":112,"text":1343},{"id":1393,"depth":112,"text":2205},"Using a method name without () when trying to call it",{"id":1440,"depth":112,"text":1441},{"id":1494,"depth":112,"text":1495},{"id":1623,"depth":80,"text":1624},{"id":1978,"depth":80,"text":1979},{"id":2100,"depth":80,"text":2101,"children":2211},[2212,2213,2215,2216],{"id":2104,"depth":112,"text":2105},{"id":2111,"depth":112,"text":2214},"Why do I need self in a class?",{"id":2123,"depth":112,"text":2124},{"id":2130,"depth":112,"text":2131},{"id":2137,"depth":80,"text":2138},"Master python basic class example oop in our comprehensive Python beginner guide.","md",{},"\u002Fexamples\u002Fpython-basic-class-example-oop",{"title":5,"description":2218},"examples\u002Fpython-basic-class-example-oop","HoyhiIDgGJNsaNyOVSC1mNHpA0Gf5OKXUfIYRwhZi9M",1777585474904]