[{"data":1,"prerenderedAt":1558},["ShallowReactive",2],{"doc-\u002Freference\u002Fpython-dir-function-explained":3},{"id":4,"title":5,"body":6,"description":1551,"extension":1552,"meta":1553,"navigation":335,"path":1554,"seo":1555,"stem":1556,"__hash__":1557},"content\u002Freference\u002Fpython-dir-function-explained.md","Python dir() Function Explained",{"type":7,"value":8,"toc":1503},"minimark",[9,19,26,29,48,58,63,119,126,129,230,233,240,245,248,259,262,276,282,286,291,298,301,349,359,364,367,418,421,435,442,448,452,485,488,507,510,514,556,558,580,583,597,602,608,611,671,674,685,688,699,702,706,712,715,745,748,763,766,769,788,791,808,818,821,855,861,867,870,878,909,912,934,937,940,954,958,989,1006,1014,1021,1025,1033,1037,1045,1048,1097,1109,1113,1116,1122,1127,1137,1141,1144,1147,1151,1154,1156,1177,1181,1187,1198,1204,1208,1214,1238,1241,1306,1309,1337,1340,1402,1406,1413,1416,1425,1433,1440,1443,1452,1458,1462,1490,1499],[10,11,13,14,18],"h1",{"id":12},"python-dir-function-explained","Python ",[15,16,17],"code",{},"dir()"," Function Explained",[20,21,22,23,25],"p",{},"The Python ",[15,24,17],{}," function is a simple inspection tool. It helps you see what names are available on an object, module, or in the current scope.",[20,27,28],{},"This is especially useful when you are:",[30,31,32,36,39,45],"ul",{},[33,34,35],"li",{},"learning Python",[33,37,38],{},"exploring a new object",[33,40,41,42],{},"debugging an ",[15,43,44],{},"AttributeError",[33,46,47],{},"checking what methods exist on a value",[20,49,50,51,53,54],{},"In short, ",[15,52,17],{}," helps you answer the question: ",[55,56,57],"strong",{},"“What can I use here?”",[59,60,62],"h2",{"id":61},"quick-example","Quick example",[64,65,70],"pre",{"className":66,"code":67,"language":68,"meta":69,"style":69},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","name = \"hello\"\nprint(dir(name))\n","python","",[15,71,72,96],{"__ignoreMap":69},[73,74,77,81,85,89,93],"span",{"class":75,"line":76},"line",1,[73,78,80],{"class":79},"su5hD","name ",[73,82,84],{"class":83},"smGrS","=",[73,86,88],{"class":87},"sjJ54"," \"",[73,90,92],{"class":91},"s_sjI","hello",[73,94,95],{"class":87},"\"\n",[73,97,99,103,107,110,112,116],{"class":75,"line":98},2,[73,100,102],{"class":101},"sptTA","print",[73,104,106],{"class":105},"sP7_E","(",[73,108,109],{"class":101},"dir",[73,111,106],{"class":105},[73,113,115],{"class":114},"slqww","name",[73,117,118],{"class":105},"))\n",[20,120,121,122,125],{},"Use ",[15,123,124],{},"dir(object)"," to see the attributes and methods available on that object.",[20,127,128],{},"Example output will include names such as:",[64,130,132],{"className":66,"code":131,"language":68,"meta":69,"style":69},"['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', ..., 'lower', 'split', 'upper']\n",[15,133,134],{"__ignoreMap":69},[73,135,136,139,142,145,147,150,153,156,158,160,162,165,167,169,171,174,176,178,180,183,185,187,189,192,194,196,200,202,204,207,209,211,213,216,218,220,222,225,227],{"class":75,"line":76},[73,137,138],{"class":105},"[",[73,140,141],{"class":87},"'",[73,143,144],{"class":91},"__add__",[73,146,141],{"class":87},[73,148,149],{"class":105},",",[73,151,152],{"class":87}," '",[73,154,155],{"class":91},"__class__",[73,157,141],{"class":87},[73,159,149],{"class":105},[73,161,152],{"class":87},[73,163,164],{"class":91},"__contains__",[73,166,141],{"class":87},[73,168,149],{"class":105},[73,170,152],{"class":87},[73,172,173],{"class":91},"__delattr__",[73,175,141],{"class":87},[73,177,149],{"class":105},[73,179,152],{"class":87},[73,181,182],{"class":91},"__dir__",[73,184,141],{"class":87},[73,186,149],{"class":105},[73,188,152],{"class":87},[73,190,191],{"class":91},"__doc__",[73,193,141],{"class":87},[73,195,149],{"class":105},[73,197,199],{"class":198},"s_hVV"," ...",[73,201,149],{"class":105},[73,203,152],{"class":87},[73,205,206],{"class":91},"lower",[73,208,141],{"class":87},[73,210,149],{"class":105},[73,212,152],{"class":87},[73,214,215],{"class":91},"split",[73,217,141],{"class":87},[73,219,149],{"class":105},[73,221,152],{"class":87},[73,223,224],{"class":91},"upper",[73,226,141],{"class":87},[73,228,229],{"class":105},"]\n",[20,231,232],{},"Notice that the result is a list of strings.",[59,234,236,237,239],{"id":235},"what-dir-does","What ",[15,238,17],{}," does",[20,241,242,244],{},[15,243,17],{}," shows the names available on an object.",[20,246,247],{},"It usually includes:",[30,249,250,253,256],{},[33,251,252],{},"attributes",[33,254,255],{},"methods",[33,257,258],{},"special Python names",[20,260,261],{},"Important points:",[30,263,264,270,273],{},[33,265,266,267],{},"The result is a ",[55,268,269],{},"list of strings",[33,271,272],{},"Each string is the name of something available on that object",[33,274,275],{},"It is often used for exploration and debugging",[20,277,278,279,281],{},"For example, if you want to know what you can do with a string, ",[15,280,17],{}," gives you a list of available names.",[59,283,285],{"id":284},"basic-syntax","Basic syntax",[20,287,288,290],{},[15,289,17],{}," can be used in two main ways.",[292,293,295,297],"h3",{"id":294},"dir-with-no-argument",[15,296,17],{}," with no argument",[20,299,300],{},"This shows names in the current scope.",[64,302,304],{"className":66,"code":303,"language":68,"meta":69,"style":69},"x = 10\nname = \"Sam\"\n\nprint(dir())\n",[15,305,306,317,330,337],{"__ignoreMap":69},[73,307,308,311,313],{"class":75,"line":76},[73,309,310],{"class":79},"x ",[73,312,84],{"class":83},[73,314,316],{"class":315},"srdBf"," 10\n",[73,318,319,321,323,325,328],{"class":75,"line":98},[73,320,80],{"class":79},[73,322,84],{"class":83},[73,324,88],{"class":87},[73,326,327],{"class":91},"Sam",[73,329,95],{"class":87},[73,331,333],{"class":75,"line":332},3,[73,334,336],{"emptyLinePlaceholder":335},true,"\n",[73,338,340,342,344,346],{"class":75,"line":339},4,[73,341,102],{"class":101},[73,343,106],{"class":105},[73,345,109],{"class":101},[73,347,348],{"class":105},"())\n",[20,350,351,352,355,356,358],{},"This will show names such as ",[15,353,354],{},"x"," and ",[15,357,115],{},", along with other names available in that scope.",[292,360,362],{"id":361},"dirobject",[15,363,124],{},[20,365,366],{},"This shows names related to a specific object.",[64,368,370],{"className":66,"code":369,"language":68,"meta":69,"style":69},"print(dir(\"hello\"))\nprint(dir([1, 2, 3]))\n",[15,371,372,391],{"__ignoreMap":69},[73,373,374,376,378,380,382,385,387,389],{"class":75,"line":76},[73,375,102],{"class":101},[73,377,106],{"class":105},[73,379,109],{"class":101},[73,381,106],{"class":105},[73,383,384],{"class":87},"\"",[73,386,92],{"class":91},[73,388,384],{"class":87},[73,390,118],{"class":105},[73,392,393,395,397,399,402,405,407,410,412,415],{"class":75,"line":98},[73,394,102],{"class":101},[73,396,106],{"class":105},[73,398,109],{"class":101},[73,400,401],{"class":105},"([",[73,403,404],{"class":315},"1",[73,406,149],{"class":105},[73,408,409],{"class":315}," 2",[73,411,149],{"class":105},[73,413,414],{"class":315}," 3",[73,416,417],{"class":105},"]))\n",[20,419,420],{},"Common objects you might inspect:",[30,422,423,426,429,432],{},[33,424,425],{},"strings",[33,427,428],{},"lists",[33,430,431],{},"modules",[33,433,434],{},"custom objects",[59,436,438,439,441],{"id":437},"using-dir-with-a-value","Using ",[15,440,17],{}," with a value",[20,443,444,445,447],{},"A common use of ",[15,446,17],{}," is passing in a value to see what methods it has.",[292,449,451],{"id":450},"example-string-methods","Example: string methods",[64,453,455],{"className":66,"code":454,"language":68,"meta":69,"style":69},"text = \"hello\"\nprint(dir(text))\n",[15,456,457,470],{"__ignoreMap":69},[73,458,459,462,464,466,468],{"class":75,"line":76},[73,460,461],{"class":79},"text ",[73,463,84],{"class":83},[73,465,88],{"class":87},[73,467,92],{"class":91},[73,469,95],{"class":87},[73,471,472,474,476,478,480,483],{"class":75,"line":98},[73,473,102],{"class":101},[73,475,106],{"class":105},[73,477,109],{"class":101},[73,479,106],{"class":105},[73,481,482],{"class":114},"text",[73,484,118],{"class":105},[20,486,487],{},"You will see method names like:",[30,489,490,494,498,502],{},[33,491,492],{},[15,493,206],{},[33,495,496],{},[15,497,224],{},[33,499,500],{},[15,501,215],{},[33,503,504],{},[15,505,506],{},"strip",[20,508,509],{},"This tells you what operations are available for strings.",[292,511,513],{"id":512},"example-list-methods","Example: list methods",[64,515,517],{"className":66,"code":516,"language":68,"meta":69,"style":69},"numbers = [1, 2, 3]\nprint(dir(numbers))\n",[15,518,519,541],{"__ignoreMap":69},[73,520,521,524,526,529,531,533,535,537,539],{"class":75,"line":76},[73,522,523],{"class":79},"numbers ",[73,525,84],{"class":83},[73,527,528],{"class":105}," [",[73,530,404],{"class":315},[73,532,149],{"class":105},[73,534,409],{"class":315},[73,536,149],{"class":105},[73,538,414],{"class":315},[73,540,229],{"class":105},[73,542,543,545,547,549,551,554],{"class":75,"line":98},[73,544,102],{"class":101},[73,546,106],{"class":105},[73,548,109],{"class":101},[73,550,106],{"class":105},[73,552,553],{"class":114},"numbers",[73,555,118],{"class":105},[20,557,487],{},[30,559,560,565,570,575],{},[33,561,562],{},[15,563,564],{},"append",[33,566,567],{},[15,568,569],{},"pop",[33,571,572],{},[15,573,574],{},"remove",[33,576,577],{},[15,578,579],{},"sort",[20,581,582],{},"This is a good way to discover what you can do with a list.",[20,584,585,586,593,594,596],{},"If you are not sure what kind of object you have, ",[587,588,590],"a",{"href":589},"\u002Freference\u002Fpython-type-function-explained",[15,591,592],{},"type()"," can help first. Then ",[15,595,17],{}," can show what names are available on that object.",[59,598,438,600,297],{"id":599},"using-dir-with-no-argument",[15,601,17],{},[20,603,604,605,607],{},"When used with no argument, ",[15,606,17],{}," shows names currently defined in your local scope.",[20,609,610],{},"This is useful when working in the Python shell.",[64,612,614],{"className":66,"code":613,"language":68,"meta":69,"style":69},"x = 5\n\ndef greet():\n    return \"Hello\"\n\nprint(dir())\n",[15,615,616,625,629,642,655,660],{"__ignoreMap":69},[73,617,618,620,622],{"class":75,"line":76},[73,619,310],{"class":79},[73,621,84],{"class":83},[73,623,624],{"class":315}," 5\n",[73,626,627],{"class":75,"line":98},[73,628,336],{"emptyLinePlaceholder":335},[73,630,631,635,639],{"class":75,"line":332},[73,632,634],{"class":633},"sbsja","def",[73,636,638],{"class":637},"sGLFI"," greet",[73,640,641],{"class":105},"():\n",[73,643,644,648,650,653],{"class":75,"line":339},[73,645,647],{"class":646},"sVHd0","    return",[73,649,88],{"class":87},[73,651,652],{"class":91},"Hello",[73,654,95],{"class":87},[73,656,658],{"class":75,"line":657},5,[73,659,336],{"emptyLinePlaceholder":335},[73,661,663,665,667,669],{"class":75,"line":662},6,[73,664,102],{"class":101},[73,666,106],{"class":105},[73,668,109],{"class":101},[73,670,348],{"class":105},[20,672,673],{},"The output will include names like:",[30,675,676,680],{},[33,677,678],{},[15,679,354],{},[33,681,682],{},[15,683,684],{},"greet",[20,686,687],{},"This is helpful for checking:",[30,689,690,693,696],{},[33,691,692],{},"what variables exist",[33,694,695],{},"what functions you have defined",[33,697,698],{},"what names are currently available",[20,700,701],{},"It is especially useful while experimenting in the interactive Python shell.",[59,703,705],{"id":704},"how-to-read-the-output","How to read the output",[20,707,708,709,711],{},"When you first use ",[15,710,17],{},", the output can look overwhelming.",[20,713,714],{},"Example:",[64,716,717],{"className":66,"code":454,"language":68,"meta":69,"style":69},[15,718,719,731],{"__ignoreMap":69},[73,720,721,723,725,727,729],{"class":75,"line":76},[73,722,461],{"class":79},[73,724,84],{"class":83},[73,726,88],{"class":87},[73,728,92],{"class":91},[73,730,95],{"class":87},[73,732,733,735,737,739,741,743],{"class":75,"line":98},[73,734,102],{"class":101},[73,736,106],{"class":105},[73,738,109],{"class":101},[73,740,106],{"class":105},[73,742,482],{"class":114},[73,744,118],{"class":105},[20,746,747],{},"You will probably see many names that start and end with double underscores, such as:",[30,749,750,754,758],{},[33,751,752],{},[15,753,155],{},[33,755,756],{},[15,757,191],{},[33,759,760],{},[15,761,762],{},"__len__",[20,764,765],{},"These are special Python names used by the language itself.",[20,767,768],{},"As a beginner, it is usually better to focus first on regular method names such as:",[30,770,771,775,779,783],{},[33,772,773],{},[15,774,224],{},[33,776,777],{},[15,778,206],{},[33,780,781],{},[15,782,215],{},[33,784,785],{},[15,786,787],{},"replace",[20,789,790],{},"A key point to remember:",[30,792,793,801],{},[33,794,795,797,798],{},[15,796,17],{}," lists ",[55,799,800],{},"names only",[33,802,803,804,807],{},"it does ",[55,805,806],{},"not"," explain what each name does",[20,809,810,811,817],{},"If you want an explanation of a method, use ",[587,812,814],{"href":813},"\u002Freference\u002Fpython-help-function-explained",[15,815,816],{},"help()",".",[20,819,820],{},"For example:",[64,822,824],{"className":66,"code":823,"language":68,"meta":69,"style":69},"name = \"hello\"\nhelp(name.upper)\n",[15,825,826,838],{"__ignoreMap":69},[73,827,828,830,832,834,836],{"class":75,"line":76},[73,829,80],{"class":79},[73,831,84],{"class":83},[73,833,88],{"class":87},[73,835,92],{"class":91},[73,837,95],{"class":87},[73,839,840,843,845,847,849,852],{"class":75,"line":98},[73,841,842],{"class":101},"help",[73,844,106],{"class":105},[73,846,115],{"class":114},[73,848,817],{"class":105},[73,850,224],{"class":851},"skxfh",[73,853,854],{"class":105},")\n",[59,856,858,860],{"id":857},"dir-on-modules",[15,859,17],{}," on modules",[20,862,863,864,866],{},"You can also use ",[15,865,17],{}," on modules after importing them.",[20,868,869],{},"This is useful when you want to explore what a module provides.",[292,871,873,874,877],{"id":872},"example-math-module","Example: ",[15,875,876],{},"math"," module",[64,879,881],{"className":66,"code":880,"language":68,"meta":69,"style":69},"import math\n\nprint(dir(math))\n",[15,882,883,891,895],{"__ignoreMap":69},[73,884,885,888],{"class":75,"line":76},[73,886,887],{"class":646},"import",[73,889,890],{"class":79}," math\n",[73,892,893],{"class":75,"line":98},[73,894,336],{"emptyLinePlaceholder":335},[73,896,897,899,901,903,905,907],{"class":75,"line":332},[73,898,102],{"class":101},[73,900,106],{"class":105},[73,902,109],{"class":101},[73,904,106],{"class":105},[73,906,876],{"class":114},[73,908,118],{"class":105},[20,910,911],{},"You may see names like:",[30,913,914,919,924,929],{},[33,915,916],{},[15,917,918],{},"sqrt",[33,920,921],{},[15,922,923],{},"ceil",[33,925,926],{},[15,927,928],{},"floor",[33,930,931],{},[15,932,933],{},"pi",[20,935,936],{},"This helps you discover available functions and constants.",[20,938,939],{},"If you are exploring modules, these pages may help too:",[30,941,942,948],{},[33,943,944],{},[587,945,947],{"href":946},"\u002Flearn\u002Fpython-modules-explained","Python modules explained",[33,949,950],{},[587,951,953],{"href":952},"\u002Fstandard-library\u002Fpython-math-module-overview","Python math module overview",[292,955,957],{"id":956},"another-example","Another example",[64,959,961],{"className":66,"code":960,"language":68,"meta":69,"style":69},"import json\n\nprint(dir(json))\n",[15,962,963,970,974],{"__ignoreMap":69},[73,964,965,967],{"class":75,"line":76},[73,966,887],{"class":646},[73,968,969],{"class":79}," json\n",[73,971,972],{"class":75,"line":98},[73,973,336],{"emptyLinePlaceholder":335},[73,975,976,978,980,982,984,987],{"class":75,"line":332},[73,977,102],{"class":101},[73,979,106],{"class":105},[73,981,109],{"class":101},[73,983,106],{"class":105},[73,985,986],{"class":114},"json",[73,988,118],{"class":105},[20,990,991,992,995,996,995,999,1002,1003,817],{},"This can help you quickly spot useful names such as ",[15,993,994],{},"dump",", ",[15,997,998],{},"dumps",[15,1000,1001],{},"load",", and ",[15,1004,1005],{},"loads",[59,1007,1009,1011,1012],{"id":1008},"dir-vs-help",[15,1010,17],{}," vs ",[15,1013,816],{},[20,1015,1016,355,1018,1020],{},[15,1017,17],{},[15,1019,816],{}," are often used together.",[292,1022,1023],{"id":109},[15,1024,17],{},[30,1026,1027,1030],{},[33,1028,1029],{},"shows available names",[33,1031,1032],{},"helps you discover methods and attributes",[292,1034,1035],{"id":842},[15,1036,816],{},[30,1038,1039,1042],{},[33,1040,1041],{},"explains what an object or function does",[33,1043,1044],{},"shows usage details and documentation",[20,1046,1047],{},"A common beginner workflow looks like this:",[64,1049,1051],{"className":66,"code":1050,"language":68,"meta":69,"style":69},"name = \"hello\"\n\nprint(dir(name))\nhelp(name.upper)\n",[15,1052,1053,1065,1069,1083],{"__ignoreMap":69},[73,1054,1055,1057,1059,1061,1063],{"class":75,"line":76},[73,1056,80],{"class":79},[73,1058,84],{"class":83},[73,1060,88],{"class":87},[73,1062,92],{"class":91},[73,1064,95],{"class":87},[73,1066,1067],{"class":75,"line":98},[73,1068,336],{"emptyLinePlaceholder":335},[73,1070,1071,1073,1075,1077,1079,1081],{"class":75,"line":332},[73,1072,102],{"class":101},[73,1074,106],{"class":105},[73,1076,109],{"class":101},[73,1078,106],{"class":105},[73,1080,115],{"class":114},[73,1082,118],{"class":105},[73,1084,1085,1087,1089,1091,1093,1095],{"class":75,"line":339},[73,1086,842],{"class":101},[73,1088,106],{"class":105},[73,1090,115],{"class":114},[73,1092,817],{"class":105},[73,1094,224],{"class":851},[73,1096,854],{"class":105},[20,1098,121,1099,1101,1102,1105,1106,1108],{},[15,1100,17],{}," first to find a method name.",[1103,1104],"br",{},"\nThen use ",[15,1107,816],{}," to understand how to use it.",[59,1110,1112],{"id":1111},"common-beginner-confusion","Common beginner confusion",[20,1114,1115],{},"Here are a few things that often confuse beginners.",[292,1117,1119,1121],{"id":1118},"dir-returns-names-not-values",[15,1120,17],{}," returns names, not values",[20,1123,1124,1126],{},[15,1125,17],{}," does not give you the actual value of an attribute. It only gives you its name.",[20,1128,1129,1130,1132,1133,1136],{},"For example, seeing ",[15,1131,224],{}," in ",[15,1134,1135],{},"dir(\"hello\")"," does not run the method. It only tells you the method exists.",[292,1138,1140],{"id":1139},"not-every-name-is-for-everyday-use","Not every name is for everyday use",[20,1142,1143],{},"Many names in the output are special Python internals, especially names with double underscores.",[20,1145,1146],{},"Beginners usually do not need most of these right away.",[292,1148,1150],{"id":1149},"output-can-vary","Output can vary",[20,1152,1153],{},"The exact output depends on the object type.",[20,1155,820],{},[30,1157,1158,1163,1169],{},[33,1159,1160,1162],{},[15,1161,1135],{}," shows string-related names",[33,1164,1165,1168],{},[15,1166,1167],{},"dir([1, 2, 3])"," shows list-related names",[33,1170,1171,1174,1175,877],{},[15,1172,1173],{},"dir(math)"," shows names from the ",[15,1176,876],{},[292,1178,1180],{"id":1179},"a-name-existing-does-not-mean-you-know-how-to-call-it","A name existing does not mean you know how to call it",[20,1182,1183,1184,1186],{},"Just because a method appears in ",[15,1185,17],{}," does not mean you already know:",[30,1188,1189,1192,1195],{},[33,1190,1191],{},"what it does",[33,1193,1194],{},"what arguments it needs",[33,1196,1197],{},"what it returns",[20,1199,1200,1201,1203],{},"That is why ",[15,1202,816],{}," is the natural next step.",[59,1205,1207],{"id":1206},"common-mistakes","Common mistakes",[20,1209,1210,1211,1213],{},"Beginners often use ",[15,1212,17],{}," in these situations:",[30,1215,1216,1219,1228,1231],{},[33,1217,1218],{},"Trying to understand what methods are available on a string, list, or dictionary",[33,1220,1221,1222,1227],{},"Seeing an ",[587,1223,1225],{"href":1224},"\u002Ferrors\u002Fattributeerror-object-has-no-attribute-fix",[15,1226,44],{}," and wanting to check valid attribute names",[33,1229,1230],{},"Exploring a module without knowing its functions",[33,1232,438,1233,1235,1236],{},[15,1234,17],{}," output without following up with documentation or ",[15,1237,816],{},[20,1239,1240],{},"A simple debugging workflow is:",[64,1242,1244],{"className":66,"code":1243,"language":68,"meta":69,"style":69},"name = \"hello\"\n\nprint(type(name))\nprint(dir(name))\nhelp(name.upper)\n",[15,1245,1246,1258,1262,1278,1292],{"__ignoreMap":69},[73,1247,1248,1250,1252,1254,1256],{"class":75,"line":76},[73,1249,80],{"class":79},[73,1251,84],{"class":83},[73,1253,88],{"class":87},[73,1255,92],{"class":91},[73,1257,95],{"class":87},[73,1259,1260],{"class":75,"line":98},[73,1261,336],{"emptyLinePlaceholder":335},[73,1263,1264,1266,1268,1272,1274,1276],{"class":75,"line":332},[73,1265,102],{"class":101},[73,1267,106],{"class":105},[73,1269,1271],{"class":1270},"sZMiF","type",[73,1273,106],{"class":105},[73,1275,115],{"class":114},[73,1277,118],{"class":105},[73,1279,1280,1282,1284,1286,1288,1290],{"class":75,"line":339},[73,1281,102],{"class":101},[73,1283,106],{"class":105},[73,1285,109],{"class":101},[73,1287,106],{"class":105},[73,1289,115],{"class":114},[73,1291,118],{"class":105},[73,1293,1294,1296,1298,1300,1302,1304],{"class":75,"line":657},[73,1295,842],{"class":101},[73,1297,106],{"class":105},[73,1299,115],{"class":114},[73,1301,817],{"class":105},[73,1303,224],{"class":851},[73,1305,854],{"class":105},[20,1307,1308],{},"And for modules:",[64,1310,1311],{"className":66,"code":880,"language":68,"meta":69,"style":69},[15,1312,1313,1319,1323],{"__ignoreMap":69},[73,1314,1315,1317],{"class":75,"line":76},[73,1316,887],{"class":646},[73,1318,890],{"class":79},[73,1320,1321],{"class":75,"line":98},[73,1322,336],{"emptyLinePlaceholder":335},[73,1324,1325,1327,1329,1331,1333,1335],{"class":75,"line":332},[73,1326,102],{"class":101},[73,1328,106],{"class":105},[73,1330,109],{"class":101},[73,1332,106],{"class":105},[73,1334,876],{"class":114},[73,1336,118],{"class":105},[20,1338,1339],{},"You can try the same commands in the Python shell:",[64,1341,1343],{"className":66,"code":1342,"language":68,"meta":69,"style":69},"python\nname = \"hello\"\ndir(name)\nhelp(name.upper)\nimport math\ndir(math)\n",[15,1344,1345,1350,1362,1372,1386,1392],{"__ignoreMap":69},[73,1346,1347],{"class":75,"line":76},[73,1348,1349],{"class":79},"python\n",[73,1351,1352,1354,1356,1358,1360],{"class":75,"line":98},[73,1353,80],{"class":79},[73,1355,84],{"class":83},[73,1357,88],{"class":87},[73,1359,92],{"class":91},[73,1361,95],{"class":87},[73,1363,1364,1366,1368,1370],{"class":75,"line":332},[73,1365,109],{"class":101},[73,1367,106],{"class":105},[73,1369,115],{"class":114},[73,1371,854],{"class":105},[73,1373,1374,1376,1378,1380,1382,1384],{"class":75,"line":339},[73,1375,842],{"class":101},[73,1377,106],{"class":105},[73,1379,115],{"class":114},[73,1381,817],{"class":105},[73,1383,224],{"class":851},[73,1385,854],{"class":105},[73,1387,1388,1390],{"class":75,"line":657},[73,1389,887],{"class":646},[73,1391,890],{"class":79},[73,1393,1394,1396,1398,1400],{"class":75,"line":662},[73,1395,109],{"class":101},[73,1397,106],{"class":105},[73,1399,876],{"class":114},[73,1401,854],{"class":105},[59,1403,1405],{"id":1404},"faq","FAQ",[292,1407,1409,1410,1412],{"id":1408},"what-does-dir-return-in-python","What does ",[15,1411,17],{}," return in Python?",[20,1414,1415],{},"It returns a list of strings containing attribute and method names for an object, or names in the current scope when called with no argument.",[292,1417,1419,1420,355,1422,1424],{"id":1418},"what-is-the-difference-between-dir-and-help","What is the difference between ",[15,1421,17],{},[15,1423,816],{},"?",[20,1426,1427,1429,1430,1432],{},[15,1428,17],{}," lists available names. ",[15,1431,816],{}," gives documentation and usage details.",[292,1434,1436,1437,1439],{"id":1435},"why-do-i-see-names-with-double-underscores-in-dir-output","Why do I see names with double underscores in ",[15,1438,17],{}," output?",[20,1441,1442],{},"Those are special Python attributes and methods used internally by the language.",[292,1444,1446,1447,1449,1450,1424],{"id":1445},"can-dir-help-fix-attributeerror","Can ",[15,1448,17],{}," help fix ",[15,1451,44],{},[20,1453,1454,1455,817],{},"Yes. It can show which attribute names actually exist on an object. This makes it useful when debugging an error like ",[587,1456,1457],{"href":1224},"object has no attribute",[59,1459,1461],{"id":1460},"see-also","See also",[30,1463,1464,1471,1476,1480,1484],{},[33,1465,1466],{},[587,1467,13,1468,1470],{"href":813},[15,1469,816],{}," function explained",[33,1472,1473],{},[587,1474,1475],{"href":1224},"AttributeError: object has no attribute fix",[33,1477,1478],{},[587,1479,947],{"href":946},[33,1481,1482],{},[587,1483,953],{"href":952},[33,1485,1486],{},[587,1487,13,1488,1470],{"href":589},[15,1489,592],{},[20,1491,1492,1493,1495,1496,1498],{},"A good habit is to use ",[15,1494,17],{}," together with ",[15,1497,816],{}," in the Python shell. It is one of the fastest ways to explore objects and learn Python methods as you go.",[1500,1501,1502],"style",{},"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 .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 .sptTA, html code.shiki .sptTA{--shiki-light:#6182B8;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}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 .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sbsja, html code.shiki .sbsja{--shiki-light:#9C3EDA;--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sGLFI, html code.shiki .sGLFI{--shiki-light:#6182B8;--shiki-default:#6F42C1;--shiki-dark:#B392F0}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 .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":69,"searchDepth":98,"depth":98,"links":1504},[1505,1506,1508,1513,1518,1520,1521,1527,1532,1539,1540,1550],{"id":61,"depth":98,"text":62},{"id":235,"depth":98,"text":1507},"What dir() does",{"id":284,"depth":98,"text":285,"children":1509},[1510,1512],{"id":294,"depth":332,"text":1511},"dir() with no argument",{"id":361,"depth":332,"text":124},{"id":437,"depth":98,"text":1514,"children":1515},"Using dir() with a value",[1516,1517],{"id":450,"depth":332,"text":451},{"id":512,"depth":332,"text":513},{"id":599,"depth":98,"text":1519},"Using dir() with no argument",{"id":704,"depth":98,"text":705},{"id":857,"depth":98,"text":1522,"children":1523},"dir() on modules",[1524,1526],{"id":872,"depth":332,"text":1525},"Example: math module",{"id":956,"depth":332,"text":957},{"id":1008,"depth":98,"text":1528,"children":1529},"dir() vs help()",[1530,1531],{"id":109,"depth":332,"text":17},{"id":842,"depth":332,"text":816},{"id":1111,"depth":98,"text":1112,"children":1533},[1534,1536,1537,1538],{"id":1118,"depth":332,"text":1535},"dir() returns names, not values",{"id":1139,"depth":332,"text":1140},{"id":1149,"depth":332,"text":1150},{"id":1179,"depth":332,"text":1180},{"id":1206,"depth":98,"text":1207},{"id":1404,"depth":98,"text":1405,"children":1541},[1542,1544,1546,1548],{"id":1408,"depth":332,"text":1543},"What does dir() return in Python?",{"id":1418,"depth":332,"text":1545},"What is the difference between dir() and help()?",{"id":1435,"depth":332,"text":1547},"Why do I see names with double underscores in dir() output?",{"id":1445,"depth":332,"text":1549},"Can dir() help fix AttributeError?",{"id":1460,"depth":98,"text":1461},"Master python dir function explained in our comprehensive Python beginner guide.","md",{},"\u002Freference\u002Fpython-dir-function-explained",{"title":5,"description":1551},"reference\u002Fpython-dir-function-explained","GdcucA4RY69afXDO9saBTHeJ2twMUyCItdFzeLoSsyo",1777585495747]