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