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