[{"data":1,"prerenderedAt":1379},["ShallowReactive",2],{"doc-\u002Flearn\u002Fpython-indentation-rules-and-why-they-matter":3},{"id":4,"title":5,"body":6,"description":1372,"extension":1373,"meta":1374,"navigation":93,"path":1375,"seo":1376,"stem":1377,"__hash__":1378},"content\u002Flearn\u002Fpython-indentation-rules-and-why-they-matter.md","Python Indentation Rules and Why They Matter",{"type":7,"value":8,"toc":1349},"minimark",[9,13,17,25,28,35,40,133,136,140,143,146,149,181,184,187,243,248,263,266,300,314,318,321,324,338,341,427,436,439,500,510,513,517,520,523,569,572,603,605,625,628,639,643,646,660,663,666,713,716,727,730,734,737,740,743,746,833,837,873,875,899,902,906,909,926,929,940,943,970,977,980,1007,1010,1053,1059,1062,1080,1084,1087,1104,1107,1110,1114,1117,1134,1137,1172,1175,1219,1222,1226,1229,1244,1251,1269,1272,1276,1280,1283,1287,1290,1294,1300,1304,1311,1315,1345],[10,11,5],"h1",{"id":12},"python-indentation-rules-and-why-they-matter",[14,15,16],"p",{},"Indentation in Python means the spaces at the beginning of a line.",[14,18,19,20,24],{},"In many programming languages, blocks of code are grouped with braces like ",[21,22,23],"code",{},"{}",". Python works differently. It uses indentation to show which lines belong together.",[14,26,27],{},"This is why indentation is not just a style choice in Python. It is part of the language syntax.",[14,29,30,31,34],{},"If you are learning Python syntax, indentation is one of the first things to understand. It affects ",[21,32,33],{},"if"," statements, loops, functions, classes, and error handling blocks.",[36,37,39],"h2",{"id":38},"quick-example","Quick example",[41,42,47],"pre",{"className":43,"code":44,"language":45,"meta":46,"style":46},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","if True:\n    print(\"Indented correctly\")\n\nfor i in range(3):\n    print(i)\n","python","",[21,48,49,65,88,95,120],{"__ignoreMap":46},[50,51,54,57,61],"span",{"class":52,"line":53},"line",1,[50,55,33],{"class":56},"sVHd0",[50,58,60],{"class":59},"s39Yj"," True",[50,62,64],{"class":63},"sP7_E",":\n",[50,66,68,72,75,79,83,85],{"class":52,"line":67},2,[50,69,71],{"class":70},"sptTA","    print",[50,73,74],{"class":63},"(",[50,76,78],{"class":77},"sjJ54","\"",[50,80,82],{"class":81},"s_sjI","Indented correctly",[50,84,78],{"class":77},[50,86,87],{"class":63},")\n",[50,89,91],{"class":52,"line":90},3,[50,92,94],{"emptyLinePlaceholder":93},true,"\n",[50,96,98,101,105,108,111,113,117],{"class":52,"line":97},4,[50,99,100],{"class":56},"for",[50,102,104],{"class":103},"su5hD"," i ",[50,106,107],{"class":56},"in",[50,109,110],{"class":70}," range",[50,112,74],{"class":63},[50,114,116],{"class":115},"srdBf","3",[50,118,119],{"class":63},"):\n",[50,121,123,125,127,131],{"class":52,"line":122},5,[50,124,71],{"class":70},[50,126,74],{"class":63},[50,128,130],{"class":129},"slqww","i",[50,132,87],{"class":63},[14,134,135],{},"Use consistent spaces for code inside blocks. A common beginner rule is: indent each block with 4 spaces.",[36,137,139],{"id":138},"what-indentation-means-in-python","What indentation means in Python",[14,141,142],{},"Indentation is the space at the start of a line.",[14,144,145],{},"Python uses that space to decide which lines belong to the same block of code.",[14,147,148],{},"A block is a group of lines that run together under statements such as:",[150,151,152,157,161,166,171,176],"ul",{},[153,154,155],"li",{},[21,156,33],{},[153,158,159],{},[21,160,100],{},[153,162,163],{},[21,164,165],{},"while",[153,167,168],{},[21,169,170],{},"def",[153,172,173],{},[21,174,175],{},"class",[153,177,178],{},[21,179,180],{},"try",[14,182,183],{},"Unlike some languages, Python does not use braces to define blocks. The indentation itself defines the block.",[14,185,186],{},"For example:",[41,188,190],{"className":43,"code":189,"language":45,"meta":46,"style":46},"if 5 > 2:\n    print(\"This line is inside the if block\")\n\nprint(\"This line is outside the if block\")\n",[21,191,192,208,223,227],{"__ignoreMap":46},[50,193,194,196,199,203,206],{"class":52,"line":53},[50,195,33],{"class":56},[50,197,198],{"class":115}," 5",[50,200,202],{"class":201},"smGrS"," >",[50,204,205],{"class":115}," 2",[50,207,64],{"class":63},[50,209,210,212,214,216,219,221],{"class":52,"line":67},[50,211,71],{"class":70},[50,213,74],{"class":63},[50,215,78],{"class":77},[50,217,218],{"class":81},"This line is inside the if block",[50,220,78],{"class":77},[50,222,87],{"class":63},[50,224,225],{"class":52,"line":90},[50,226,94],{"emptyLinePlaceholder":93},[50,228,229,232,234,236,239,241],{"class":52,"line":97},[50,230,231],{"class":70},"print",[50,233,74],{"class":63},[50,235,78],{"class":77},[50,237,238],{"class":81},"This line is outside the if block",[50,240,78],{"class":77},[50,242,87],{"class":63},[244,245,247],"h3",{"id":246},"what-this-code-does","What this code does",[150,249,250,256],{},[153,251,252,253,255],{},"The line with 4 spaces belongs to the ",[21,254,33],{}," block",[153,257,258,259,262],{},"The last ",[21,260,261],{},"print()"," line is not indented, so it is outside the block",[14,264,265],{},"Output:",[41,267,269],{"className":43,"code":268,"language":45,"meta":46,"style":46},"This line is inside the if block\nThis line is outside the if block\n",[21,270,271,287],{"__ignoreMap":46},[50,272,273,276,279,282,284],{"class":52,"line":53},[50,274,275],{"class":103},"This line ",[50,277,278],{"class":201},"is",[50,280,281],{"class":103}," inside the ",[50,283,33],{"class":56},[50,285,286],{"class":103}," block\n",[50,288,289,291,293,296,298],{"class":52,"line":67},[50,290,275],{"class":103},[50,292,278],{"class":201},[50,294,295],{"class":103}," outside the ",[50,297,33],{"class":56},[50,299,286],{"class":103},[14,301,302,303,308,309,313],{},"If you are new to Python structure, this idea also appears in ",[304,305,307],"a",{"href":306},"\u002Flearn\u002Fpython-if-statements-explained\u002F","Python if statements explained"," and ",[304,310,312],{"href":311},"\u002Flearn\u002Fpython-functions-explained\u002F","Python functions explained",".",[36,315,317],{"id":316},"why-indentation-matters","Why indentation matters",[14,319,320],{},"Indentation matters because it tells Python where a block starts and ends.",[14,322,323],{},"This affects both correctness and meaning.",[150,325,326,329,332,335],{},[153,327,328],{},"It tells Python where a block starts and ends",[153,330,331],{},"Wrong indentation can change program behavior",[153,333,334],{},"Missing indentation can cause an error",[153,336,337],{},"Inconsistent indentation makes code harder to read",[14,339,340],{},"Look at this example:",[41,342,344],{"className":43,"code":343,"language":45,"meta":46,"style":46},"age = 18\n\nif age >= 18:\n    print(\"Adult\")\n    print(\"You can vote\")\n\nprint(\"Done\")\n",[21,345,346,357,361,376,391,406,411],{"__ignoreMap":46},[50,347,348,351,354],{"class":52,"line":53},[50,349,350],{"class":103},"age ",[50,352,353],{"class":201},"=",[50,355,356],{"class":115}," 18\n",[50,358,359],{"class":52,"line":67},[50,360,94],{"emptyLinePlaceholder":93},[50,362,363,365,368,371,374],{"class":52,"line":90},[50,364,33],{"class":56},[50,366,367],{"class":103}," age ",[50,369,370],{"class":201},">=",[50,372,373],{"class":115}," 18",[50,375,64],{"class":63},[50,377,378,380,382,384,387,389],{"class":52,"line":97},[50,379,71],{"class":70},[50,381,74],{"class":63},[50,383,78],{"class":77},[50,385,386],{"class":81},"Adult",[50,388,78],{"class":77},[50,390,87],{"class":63},[50,392,393,395,397,399,402,404],{"class":52,"line":122},[50,394,71],{"class":70},[50,396,74],{"class":63},[50,398,78],{"class":77},[50,400,401],{"class":81},"You can vote",[50,403,78],{"class":77},[50,405,87],{"class":63},[50,407,409],{"class":52,"line":408},6,[50,410,94],{"emptyLinePlaceholder":93},[50,412,414,416,418,420,423,425],{"class":52,"line":413},7,[50,415,231],{"class":70},[50,417,74],{"class":63},[50,419,78],{"class":77},[50,421,422],{"class":81},"Done",[50,424,78],{"class":77},[50,426,87],{"class":63},[14,428,429,430,432,433,435],{},"Here, both indented ",[21,431,261],{}," lines are part of the ",[21,434,33],{}," block.",[14,437,438],{},"Now compare it to this:",[41,440,442],{"className":43,"code":441,"language":45,"meta":46,"style":46},"age = 18\n\nif age >= 18:\n    print(\"Adult\")\n\nprint(\"You can vote\")\n",[21,443,444,452,456,468,482,486],{"__ignoreMap":46},[50,445,446,448,450],{"class":52,"line":53},[50,447,350],{"class":103},[50,449,353],{"class":201},[50,451,356],{"class":115},[50,453,454],{"class":52,"line":67},[50,455,94],{"emptyLinePlaceholder":93},[50,457,458,460,462,464,466],{"class":52,"line":90},[50,459,33],{"class":56},[50,461,367],{"class":103},[50,463,370],{"class":201},[50,465,373],{"class":115},[50,467,64],{"class":63},[50,469,470,472,474,476,478,480],{"class":52,"line":97},[50,471,71],{"class":70},[50,473,74],{"class":63},[50,475,78],{"class":77},[50,477,386],{"class":81},[50,479,78],{"class":77},[50,481,87],{"class":63},[50,483,484],{"class":52,"line":122},[50,485,94],{"emptyLinePlaceholder":93},[50,487,488,490,492,494,496,498],{"class":52,"line":408},[50,489,231],{"class":70},[50,491,74],{"class":63},[50,493,78],{"class":77},[50,495,401],{"class":81},[50,497,78],{"class":77},[50,499,87],{"class":63},[14,501,502,503,505,506,509],{},"The second version is valid Python, but it means something different. The last line is outside the ",[21,504,33],{}," block, so it will run no matter what ",[21,507,508],{},"age"," is.",[14,511,512],{},"Small indentation changes can change how your program works.",[36,514,516],{"id":515},"where-indentation-is-required","Where indentation is required",[14,518,519],{},"Indentation is required after statements that introduce a block.",[14,521,522],{},"You will use it in places like these:",[150,524,525,539,547,552,557],{},[153,526,527,528,530,531,534,535,538],{},"After ",[21,529,33],{},", ",[21,532,533],{},"elif",", and ",[21,536,537],{},"else"," blocks",[153,540,541,542,308,544,546],{},"Inside ",[21,543,100],{},[21,545,165],{}," loops",[153,548,549,550],{},"Inside functions created with ",[21,551,170],{},[153,553,554,555],{},"Inside classes created with ",[21,556,175],{},[153,558,541,559,530,561,530,564,534,566,538],{},[21,560,180],{},[21,562,563],{},"except",[21,565,537],{},[21,567,568],{},"finally",[14,570,571],{},"Here is a simple example with a loop:",[41,573,575],{"className":43,"code":574,"language":45,"meta":46,"style":46},"for i in range(3):\n    print(i)\n",[21,576,577,593],{"__ignoreMap":46},[50,578,579,581,583,585,587,589,591],{"class":52,"line":53},[50,580,100],{"class":56},[50,582,104],{"class":103},[50,584,107],{"class":56},[50,586,110],{"class":70},[50,588,74],{"class":63},[50,590,116],{"class":115},[50,592,119],{"class":63},[50,594,595,597,599,601],{"class":52,"line":67},[50,596,71],{"class":70},[50,598,74],{"class":63},[50,600,130],{"class":129},[50,602,87],{"class":63},[14,604,265],{},[41,606,608],{"className":43,"code":607,"language":45,"meta":46,"style":46},"0\n1\n2\n",[21,609,610,615,620],{"__ignoreMap":46},[50,611,612],{"class":52,"line":53},[50,613,614],{"class":115},"0\n",[50,616,617],{"class":52,"line":67},[50,618,619],{"class":115},"1\n",[50,621,622],{"class":52,"line":90},[50,623,624],{"class":115},"2\n",[14,626,627],{},"Without the indentation, Python does not know which line belongs to the loop.",[14,629,630,631,308,635,313],{},"If you want to learn these block types in more detail, see ",[304,632,634],{"href":633},"\u002Flearn\u002Fpython-for-loops-explained\u002F","Python for loops explained",[304,636,638],{"href":637},"\u002Flearn\u002Fpython-syntax-basics-explained\u002F","Python syntax basics explained",[36,640,642],{"id":641},"the-standard-beginner-rule","The standard beginner rule",[14,644,645],{},"A simple rule for beginners is:",[150,647,648,651,654,657],{},[153,649,650],{},"Use 4 spaces for each indentation level",[153,652,653],{},"Keep the same indentation style throughout a file",[153,655,656],{},"Do not mix tabs and spaces",[153,658,659],{},"Most code editors can insert 4 spaces automatically",[14,661,662],{},"This is the standard Python style and the easiest habit to follow.",[14,664,665],{},"Good example:",[41,667,669],{"className":43,"code":668,"language":45,"meta":46,"style":46},"def say_hello():\n    print(\"Hello\")\n    print(\"Welcome\")\n",[21,670,671,683,698],{"__ignoreMap":46},[50,672,673,676,680],{"class":52,"line":53},[50,674,170],{"class":675},"sbsja",[50,677,679],{"class":678},"sGLFI"," say_hello",[50,681,682],{"class":63},"():\n",[50,684,685,687,689,691,694,696],{"class":52,"line":67},[50,686,71],{"class":70},[50,688,74],{"class":63},[50,690,78],{"class":77},[50,692,693],{"class":81},"Hello",[50,695,78],{"class":77},[50,697,87],{"class":63},[50,699,700,702,704,706,709,711],{"class":52,"line":90},[50,701,71],{"class":70},[50,703,74],{"class":63},[50,705,78],{"class":77},[50,707,708],{"class":81},"Welcome",[50,710,78],{"class":77},[50,712,87],{"class":63},[14,714,715],{},"Less safe for beginners:",[150,717,718,721,724],{},[153,719,720],{},"Using tabs in one place",[153,722,723],{},"Using spaces in another place",[153,725,726],{},"Using 2 spaces on one line and 4 on another",[14,728,729],{},"Even if code looks aligned on your screen, Python may still see the indentation as different.",[36,731,733],{"id":732},"how-indentation-changes-code-meaning","How indentation changes code meaning",[14,735,736],{},"Lines at the same indentation level belong to the same block.",[14,738,739],{},"A line indented further is nested inside another block.",[14,741,742],{},"A line moved back to the left ends the current block.",[14,744,745],{},"Here is an example:",[41,747,749],{"className":43,"code":748,"language":45,"meta":46,"style":46},"for i in range(2):\n    print(\"Outer loop\")\n    if i == 1:\n        print(\"Inner block\")\n\nprint(\"Finished\")\n",[21,750,751,768,783,798,814,818],{"__ignoreMap":46},[50,752,753,755,757,759,761,763,766],{"class":52,"line":53},[50,754,100],{"class":56},[50,756,104],{"class":103},[50,758,107],{"class":56},[50,760,110],{"class":70},[50,762,74],{"class":63},[50,764,765],{"class":115},"2",[50,767,119],{"class":63},[50,769,770,772,774,776,779,781],{"class":52,"line":67},[50,771,71],{"class":70},[50,773,74],{"class":63},[50,775,78],{"class":77},[50,777,778],{"class":81},"Outer loop",[50,780,78],{"class":77},[50,782,87],{"class":63},[50,784,785,788,790,793,796],{"class":52,"line":90},[50,786,787],{"class":56},"    if",[50,789,104],{"class":103},[50,791,792],{"class":201},"==",[50,794,795],{"class":115}," 1",[50,797,64],{"class":63},[50,799,800,803,805,807,810,812],{"class":52,"line":97},[50,801,802],{"class":70},"        print",[50,804,74],{"class":63},[50,806,78],{"class":77},[50,808,809],{"class":81},"Inner block",[50,811,78],{"class":77},[50,813,87],{"class":63},[50,815,816],{"class":52,"line":122},[50,817,94],{"emptyLinePlaceholder":93},[50,819,820,822,824,826,829,831],{"class":52,"line":408},[50,821,231],{"class":70},[50,823,74],{"class":63},[50,825,78],{"class":77},[50,827,828],{"class":81},"Finished",[50,830,78],{"class":77},[50,832,87],{"class":63},[244,834,836],{"id":835},"how-python-reads-this","How Python reads this",[150,838,839,848,856,867],{},[153,840,841,844,845,847],{},[21,842,843],{},"print(\"Outer loop\")"," is inside the ",[21,846,100],{}," loop",[153,849,850,853,854,847],{},[21,851,852],{},"if i == 1:"," is also inside the ",[21,855,100],{},[153,857,858,861,862,864,865,255],{},[21,859,860],{},"print(\"Inner block\")"," is inside both the ",[21,863,100],{}," loop and the ",[21,866,33],{},[153,868,869,872],{},[21,870,871],{},"print(\"Finished\")"," is outside all blocks",[14,874,265],{},[41,876,878],{"className":43,"code":877,"language":45,"meta":46,"style":46},"Outer loop\nOuter loop\nInner block\nFinished\n",[21,879,880,885,889,894],{"__ignoreMap":46},[50,881,882],{"class":52,"line":53},[50,883,884],{"class":103},"Outer loop\n",[50,886,887],{"class":52,"line":67},[50,888,884],{"class":103},[50,890,891],{"class":52,"line":90},[50,892,893],{"class":103},"Inner block\n",[50,895,896],{"class":52,"line":97},[50,897,898],{"class":103},"Finished\n",[14,900,901],{},"This nesting is a basic part of Python program structure.",[36,903,905],{"id":904},"common-indentation-errors-beginners-see","Common indentation errors beginners see",[14,907,908],{},"Beginners often see these errors:",[150,910,911,916,921],{},[153,912,913],{},[21,914,915],{},"IndentationError: expected an indented block",[153,917,918],{},[21,919,920],{},"IndentationError: unexpected indent",[153,922,923],{},[21,924,925],{},"unindent does not match any outer indentation level",[14,927,928],{},"These usually happen:",[150,930,931,934,937],{},[153,932,933],{},"after a line ending with a colon",[153,935,936],{},"when tabs and spaces are mixed",[153,938,939],{},"when one line is indented more or less than Python expects",[14,941,942],{},"Example that causes an error:",[41,944,946],{"className":43,"code":945,"language":45,"meta":46,"style":46},"if True:\nprint(\"Hello\")\n",[21,947,948,956],{"__ignoreMap":46},[50,949,950,952,954],{"class":52,"line":53},[50,951,33],{"class":56},[50,953,60],{"class":59},[50,955,64],{"class":63},[50,957,958,960,962,964,966,968],{"class":52,"line":67},[50,959,231],{"class":70},[50,961,74],{"class":63},[50,963,78],{"class":77},[50,965,693],{"class":81},[50,967,78],{"class":77},[50,969,87],{"class":63},[14,971,972,973,976],{},"This raises an indentation error because the line after ",[21,974,975],{},"if True:"," must be indented.",[14,978,979],{},"Correct version:",[41,981,983],{"className":43,"code":982,"language":45,"meta":46,"style":46},"if True:\n    print(\"Hello\")\n",[21,984,985,993],{"__ignoreMap":46},[50,986,987,989,991],{"class":52,"line":53},[50,988,33],{"class":56},[50,990,60],{"class":59},[50,992,64],{"class":63},[50,994,995,997,999,1001,1003,1005],{"class":52,"line":67},[50,996,71],{"class":70},[50,998,74],{"class":63},[50,1000,78],{"class":77},[50,1002,693],{"class":81},[50,1004,78],{"class":77},[50,1006,87],{"class":63},[14,1008,1009],{},"Another example:",[41,1011,1013],{"className":43,"code":1012,"language":45,"meta":46,"style":46},"if True:\n    print(\"Hello\")\n      print(\"World\")\n",[21,1014,1015,1023,1037],{"__ignoreMap":46},[50,1016,1017,1019,1021],{"class":52,"line":53},[50,1018,33],{"class":56},[50,1020,60],{"class":59},[50,1022,64],{"class":63},[50,1024,1025,1027,1029,1031,1033,1035],{"class":52,"line":67},[50,1026,71],{"class":70},[50,1028,74],{"class":63},[50,1030,78],{"class":77},[50,1032,693],{"class":81},[50,1034,78],{"class":77},[50,1036,87],{"class":63},[50,1038,1039,1042,1044,1046,1049,1051],{"class":52,"line":90},[50,1040,1041],{"class":70},"      print",[50,1043,74],{"class":63},[50,1045,78],{"class":77},[50,1047,1048],{"class":81},"World",[50,1050,78],{"class":77},[50,1052,87],{"class":63},[14,1054,1055,1056,1058],{},"This can raise an indentation error because the second ",[21,1057,261],{}," line has a different indentation level that does not match the block structure.",[14,1060,1061],{},"If you are trying to fix a real error message, these pages can help:",[150,1063,1064,1069,1074],{},[153,1065,1066],{},[304,1067,915],{"href":1068},"\u002Ferrors\u002Findentationerror-expected-an-indented-block-fix\u002F",[153,1070,1071],{},[304,1072,920],{"href":1073},"\u002Ferrors\u002Findentationerror-unexpected-indent-fix\u002F",[153,1075,1076],{},[304,1077,1079],{"href":1078},"\u002Ferrors\u002Findentationerror-in-python-causes-and-fixes\u002F","IndentationError in Python: causes and fixes",[36,1081,1083],{"id":1082},"how-to-avoid-indentation-problems","How to avoid indentation problems",[14,1085,1086],{},"You can prevent most indentation problems with a few habits:",[150,1088,1089,1092,1095,1098,1101],{},[153,1090,1091],{},"Use a code editor instead of a plain text editor",[153,1093,1094],{},"Turn on visible whitespace if your editor supports it",[153,1096,1097],{},"Use auto-formatting or reindent tools",[153,1099,1100],{},"Check the line after statements ending with a colon",[153,1102,1103],{},"If an error appears, compare the spaces on nearby lines",[14,1105,1106],{},"It also helps to type code yourself when learning, instead of only copy-pasting it.",[14,1108,1109],{},"If you do paste code from another source, check whether the indentation stayed consistent.",[36,1111,1113],{"id":1112},"common-mistakes","Common mistakes",[14,1115,1116],{},"These are the most common causes of indentation problems:",[150,1118,1119,1122,1125,1128,1131],{},[153,1120,1121],{},"Forgetting to indent after a colon",[153,1123,1124],{},"Mixing tabs and spaces",[153,1126,1127],{},"Indenting a line that should not be indented",[153,1129,1130],{},"Using different numbers of spaces in the same block",[153,1132,1133],{},"Copy-pasting code from different editors",[14,1135,1136],{},"For example, this is wrong because the second line should not be indented:",[41,1138,1140],{"className":43,"code":1139,"language":45,"meta":46,"style":46},"print(\"Start\")\n    print(\"Wrong indent\")\n",[21,1141,1142,1157],{"__ignoreMap":46},[50,1143,1144,1146,1148,1150,1153,1155],{"class":52,"line":53},[50,1145,231],{"class":70},[50,1147,74],{"class":63},[50,1149,78],{"class":77},[50,1151,1152],{"class":81},"Start",[50,1154,78],{"class":77},[50,1156,87],{"class":63},[50,1158,1159,1161,1163,1165,1168,1170],{"class":52,"line":67},[50,1160,71],{"class":70},[50,1162,74],{"class":63},[50,1164,78],{"class":77},[50,1166,1167],{"class":81},"Wrong indent",[50,1169,78],{"class":77},[50,1171,87],{"class":63},[14,1173,1174],{},"And this is wrong because the block uses inconsistent spacing:",[41,1176,1178],{"className":43,"code":1177,"language":45,"meta":46,"style":46},"if True:\n    print(\"Line 1\")\n  print(\"Line 2\")\n",[21,1179,1180,1188,1203],{"__ignoreMap":46},[50,1181,1182,1184,1186],{"class":52,"line":53},[50,1183,33],{"class":56},[50,1185,60],{"class":59},[50,1187,64],{"class":63},[50,1189,1190,1192,1194,1196,1199,1201],{"class":52,"line":67},[50,1191,71],{"class":70},[50,1193,74],{"class":63},[50,1195,78],{"class":77},[50,1197,1198],{"class":81},"Line 1",[50,1200,78],{"class":77},[50,1202,87],{"class":63},[50,1204,1205,1208,1210,1212,1215,1217],{"class":52,"line":90},[50,1206,1207],{"class":70},"  print",[50,1209,74],{"class":63},[50,1211,78],{"class":77},[50,1213,1214],{"class":81},"Line 2",[50,1216,78],{"class":77},[50,1218,87],{"class":63},[14,1220,1221],{},"A good debugging habit is to look at the lines just above and below the error location.",[36,1223,1225],{"id":1224},"useful-commands-for-debugging","Useful commands for debugging",[14,1227,1228],{},"Run your file normally:",[41,1230,1234],{"className":1231,"code":1232,"language":1233,"meta":46,"style":46},"language-bash shiki shiki-themes material-theme-lighter github-light github-dark","python your_file.py\n","bash",[21,1235,1236],{"__ignoreMap":46},[50,1237,1238,1241],{"class":52,"line":53},[50,1239,45],{"class":1240},"sbgvK",[50,1242,1243],{"class":81}," your_file.py\n",[14,1245,1246,1247,1250],{},"You can also use Python's ",[21,1248,1249],{},"tabnanny"," tool to check indentation problems:",[41,1252,1254],{"className":1231,"code":1253,"language":1233,"meta":46,"style":46},"python -m tabnanny your_file.py\n",[21,1255,1256],{"__ignoreMap":46},[50,1257,1258,1260,1264,1267],{"class":52,"line":53},[50,1259,45],{"class":1240},[50,1261,1263],{"class":1262},"stzsN"," -m",[50,1265,1266],{"class":81}," tabnanny",[50,1268,1243],{"class":81},[14,1270,1271],{},"This can help detect inconsistent indentation, especially when tabs and spaces are mixed.",[36,1273,1275],{"id":1274},"faq","FAQ",[244,1277,1279],{"id":1278},"how-many-spaces-should-i-use-for-indentation-in-python","How many spaces should I use for indentation in Python?",[14,1281,1282],{},"Use 4 spaces for each indentation level. This is the standard style and the easiest rule for beginners.",[244,1284,1286],{"id":1285},"can-i-use-tabs-instead-of-spaces-in-python","Can I use tabs instead of spaces in Python?",[14,1288,1289],{},"You can in some cases, but beginners should avoid tabs. Mixing tabs and spaces often causes indentation errors.",[244,1291,1293],{"id":1292},"why-does-python-care-about-indentation","Why does Python care about indentation?",[14,1295,1296,1297,1299],{},"Python uses indentation to define blocks of code, such as the body of an ",[21,1298,33],{}," statement or loop.",[244,1301,1303],{"id":1302},"what-happens-if-indentation-is-wrong","What happens if indentation is wrong?",[14,1305,1306,1307,1310],{},"Python may raise an ",[21,1308,1309],{},"IndentationError",", or the code may run with different logic than you expected.",[36,1312,1314],{"id":1313},"see-also","See also",[150,1316,1317,1321,1325,1329,1333,1337,1341],{},[153,1318,1319],{},[304,1320,638],{"href":637},[153,1322,1323],{},[304,1324,307],{"href":306},[153,1326,1327],{},[304,1328,634],{"href":633},[153,1330,1331],{},[304,1332,312],{"href":311},[153,1334,1335],{},[304,1336,915],{"href":1068},[153,1338,1339],{},[304,1340,920],{"href":1073},[153,1342,1343],{},[304,1344,1079],{"href":1078},[1346,1347,1348],"style",{},"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 .s39Yj, html code.shiki .s39Yj{--shiki-light:#39ADB5;--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 .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 .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .slqww, html code.shiki .slqww{--shiki-light:#6182B8;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html .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 .smGrS, html code.shiki .smGrS{--shiki-light:#39ADB5;--shiki-default:#D73A49;--shiki-dark:#F97583}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 .sbgvK, html code.shiki .sbgvK{--shiki-light:#E2931D;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .stzsN, html code.shiki .stzsN{--shiki-light:#91B859;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":46,"searchDepth":67,"depth":67,"links":1350},[1351,1352,1355,1356,1357,1358,1361,1362,1363,1364,1365,1371],{"id":38,"depth":67,"text":39},{"id":138,"depth":67,"text":139,"children":1353},[1354],{"id":246,"depth":90,"text":247},{"id":316,"depth":67,"text":317},{"id":515,"depth":67,"text":516},{"id":641,"depth":67,"text":642},{"id":732,"depth":67,"text":733,"children":1359},[1360],{"id":835,"depth":90,"text":836},{"id":904,"depth":67,"text":905},{"id":1082,"depth":67,"text":1083},{"id":1112,"depth":67,"text":1113},{"id":1224,"depth":67,"text":1225},{"id":1274,"depth":67,"text":1275,"children":1366},[1367,1368,1369,1370],{"id":1278,"depth":90,"text":1279},{"id":1285,"depth":90,"text":1286},{"id":1292,"depth":90,"text":1293},{"id":1302,"depth":90,"text":1303},{"id":1313,"depth":67,"text":1314},"Master python indentation rules and why they matter in our comprehensive Python beginner guide.","md",{},"\u002Flearn\u002Fpython-indentation-rules-and-why-they-matter",{"title":5,"description":1372},"learn\u002Fpython-indentation-rules-and-why-they-matter","rzvKaMBhlmm40zum1GVDT2TVXfZMjBMu74EjUoUBuU4",1777585494818]