[{"data":1,"prerenderedAt":1809},["ShallowReactive",2],{"doc-\u002Flearn\u002Fpython-syntax-basics-explained":3},{"id":4,"title":5,"body":6,"description":1802,"extension":1803,"meta":1804,"navigation":83,"path":1805,"seo":1806,"stem":1807,"__hash__":1808},"content\u002Flearn\u002Fpython-syntax-basics-explained.md","Python Syntax Basics Explained",{"type":7,"value":8,"toc":1776},"minimark",[9,13,17,25,30,33,121,124,154,157,166,170,173,176,184,196,200,208,211,243,246,267,274,278,281,284,334,337,340,348,351,355,358,361,364,408,418,421,464,467,470,481,493,497,503,506,532,537,585,588,603,606,643,650,654,660,662,687,690,693,704,706,736,739,746,750,757,760,776,778,805,808,811,838,846,860,867,871,874,876,896,902,909,936,939,951,954,983,986,1003,1006,1030,1037,1041,1044,1136,1139,1175,1178,1202,1205,1226,1230,1233,1270,1273,1278,1321,1324,1334,1337,1380,1384,1427,1429,1437,1439,1481,1485,1501,1503,1513,1515,1534,1538,1557,1559,1567,1569,1587,1590,1605,1608,1628,1631,1647,1653,1674,1680,1684,1688,1691,1695,1701,1705,1717,1721,1724,1728,1731,1735,1766,1772],[10,11,5],"h1",{"id":12},"python-syntax-basics-explained",[14,15,16],"p",{},"Python syntax is the set of rules for writing Python code correctly. If your code follows these rules, Python can read and run it.",[14,18,19,20,24],{},"This page explains the basic writing rules you need before learning variables, ",[21,22,23],"code",{},"if"," statements, loops, and functions. The goal is simple: help you read and write small pieces of valid Python code.",[26,27,29],"h2",{"id":28},"quick-example","Quick example",[14,31,32],{},"Use this small example to see the main syntax rules in one place:",[34,35,40],"pre",{"className":36,"code":37,"language":38,"meta":39,"style":39},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","name = \"Sam\"\nage = 12\n\nif age > 10:\n    print(name)\n","python","",[21,41,42,66,78,85,104],{"__ignoreMap":39},[43,44,47,51,55,59,63],"span",{"class":45,"line":46},"line",1,[43,48,50],{"class":49},"su5hD","name ",[43,52,54],{"class":53},"smGrS","=",[43,56,58],{"class":57},"sjJ54"," \"",[43,60,62],{"class":61},"s_sjI","Sam",[43,64,65],{"class":57},"\"\n",[43,67,69,72,74],{"class":45,"line":68},2,[43,70,71],{"class":49},"age ",[43,73,54],{"class":53},[43,75,77],{"class":76},"srdBf"," 12\n",[43,79,81],{"class":45,"line":80},3,[43,82,84],{"emptyLinePlaceholder":83},true,"\n",[43,86,88,91,94,97,100],{"class":45,"line":87},4,[43,89,23],{"class":90},"sVHd0",[43,92,93],{"class":49}," age ",[43,95,96],{"class":53},">",[43,98,99],{"class":76}," 10",[43,101,103],{"class":102},"sP7_E",":\n",[43,105,107,111,114,118],{"class":45,"line":106},5,[43,108,110],{"class":109},"sptTA","    print",[43,112,113],{"class":102},"(",[43,115,117],{"class":116},"slqww","name",[43,119,120],{"class":102},")\n",[14,122,123],{},"What this shows:",[125,126,127,133,139,145],"ul",{},[128,129,130,132],"li",{},[21,131,54],{}," assigns a value to a variable",[128,134,135,138],{},[21,136,137],{},"\"Sam\""," is a string, so it uses quotes",[128,140,141,144],{},[21,142,143],{},"if age > 10:"," ends with a colon",[128,146,147,150,151,153],{},[21,148,149],{},"print(name)"," is indented because it belongs inside the ",[21,152,23],{}," block",[14,155,156],{},"Output:",[34,158,160],{"className":36,"code":159,"language":38,"meta":39,"style":39},"Sam\n",[21,161,162],{"__ignoreMap":39},[43,163,164],{"class":45,"line":46},[43,165,159],{"class":49},[26,167,169],{"id":168},"what-python-syntax-means","What Python syntax means",[14,171,172],{},"Syntax means the rules for writing Python code in a form Python understands.",[14,174,175],{},"Think of it like grammar in a language:",[125,177,178,181],{},[128,179,180],{},"If the rules are correct, the meaning is clear",[128,182,183],{},"If the rules are broken, Python cannot run the code",[14,185,186,187,195],{},"This page focuses on the basic writing rules beginners need most. It does not go deep into error fixing, but if your code will not run, see ",[188,189,191,192],"a",{"href":190},"\u002Ferrors\u002Fsyntaxerror-invalid-syntax-fix\u002F","how to fix ",[21,193,194],{},"SyntaxError: invalid syntax",".",[26,197,199],{"id":198},"a-simple-python-statement","A simple Python statement",[14,201,202,203,207],{},"A ",[204,205,206],"strong",{},"statement"," is one instruction Python can run.",[14,209,210],{},"Examples:",[34,212,214],{"className":36,"code":213,"language":38,"meta":39,"style":39},"print(\"Hello\")\nx = 5\n",[21,215,216,233],{"__ignoreMap":39},[43,217,218,221,223,226,229,231],{"class":45,"line":46},[43,219,220],{"class":109},"print",[43,222,113],{"class":102},[43,224,225],{"class":57},"\"",[43,227,228],{"class":61},"Hello",[43,230,225],{"class":57},[43,232,120],{"class":102},[43,234,235,238,240],{"class":45,"line":68},[43,236,237],{"class":49},"x ",[43,239,54],{"class":53},[43,241,242],{"class":76}," 5\n",[14,244,245],{},"What these statements do:",[125,247,248,254],{},[128,249,250,253],{},[21,251,252],{},"print(\"Hello\")"," displays text",[128,255,256,259,260,263,264],{},[21,257,258],{},"x = 5"," stores the number ",[21,261,262],{},"5"," in a variable named ",[21,265,266],{},"x",[14,268,269,270,195],{},"Many beginner programs are just small statements written one after another. If you want to learn the difference between statements and expressions later, see ",[188,271,273],{"href":272},"\u002Flearn\u002Funderstanding-python-statements-and-expressions\u002F","understanding Python statements and expressions",[26,275,277],{"id":276},"how-python-uses-new-lines","How Python uses new lines",[14,279,280],{},"In Python, a statement usually ends at the end of a line.",[14,282,283],{},"For example:",[34,285,287],{"className":36,"code":286,"language":38,"meta":39,"style":39},"print(\"One\")\nprint(\"Two\")\nprint(\"Three\")\n",[21,288,289,304,319],{"__ignoreMap":39},[43,290,291,293,295,297,300,302],{"class":45,"line":46},[43,292,220],{"class":109},[43,294,113],{"class":102},[43,296,225],{"class":57},[43,298,299],{"class":61},"One",[43,301,225],{"class":57},[43,303,120],{"class":102},[43,305,306,308,310,312,315,317],{"class":45,"line":68},[43,307,220],{"class":109},[43,309,113],{"class":102},[43,311,225],{"class":57},[43,313,314],{"class":61},"Two",[43,316,225],{"class":57},[43,318,120],{"class":102},[43,320,321,323,325,327,330,332],{"class":45,"line":80},[43,322,220],{"class":109},[43,324,113],{"class":102},[43,326,225],{"class":57},[43,328,329],{"class":61},"Three",[43,331,225],{"class":57},[43,333,120],{"class":102},[14,335,336],{},"Python reads this as three separate statements.",[14,338,339],{},"Because of this, beginner code is usually written as:",[125,341,342,345],{},[128,343,344],{},"one statement per line",[128,346,347],{},"in a clear top-to-bottom order",[14,349,350],{},"Some long statements can continue across lines, but that is not something you need right away. For now, the safest habit is to write one complete instruction on each line.",[26,352,354],{"id":353},"indentation-is-part-of-python-syntax","Indentation is part of Python syntax",[14,356,357],{},"In many languages, spaces at the start of a line are just for style. In Python, they are part of the syntax.",[14,359,360],{},"Indentation tells Python that a line belongs inside a block.",[14,362,363],{},"Example:",[34,365,367],{"className":36,"code":366,"language":38,"meta":39,"style":39},"age = 12\n\nif age > 10:\n    print(\"Older than ten\")\n",[21,368,369,377,381,393],{"__ignoreMap":39},[43,370,371,373,375],{"class":45,"line":46},[43,372,71],{"class":49},[43,374,54],{"class":53},[43,376,77],{"class":76},[43,378,379],{"class":45,"line":68},[43,380,84],{"emptyLinePlaceholder":83},[43,382,383,385,387,389,391],{"class":45,"line":80},[43,384,23],{"class":90},[43,386,93],{"class":49},[43,388,96],{"class":53},[43,390,99],{"class":76},[43,392,103],{"class":102},[43,394,395,397,399,401,404,406],{"class":45,"line":87},[43,396,110],{"class":109},[43,398,113],{"class":102},[43,400,225],{"class":57},[43,402,403],{"class":61},"Older than ten",[43,405,225],{"class":57},[43,407,120],{"class":102},[14,409,410,411,414,415,417],{},"Here, ",[21,412,413],{},"print(\"Older than ten\")"," is indented, so Python knows it belongs inside the ",[21,416,23],{}," statement.",[14,419,420],{},"Without indentation, the code is not valid:",[34,422,424],{"className":36,"code":423,"language":38,"meta":39,"style":39},"age = 12\n\nif age > 10:\nprint(\"Older than ten\")\n",[21,425,426,434,438,450],{"__ignoreMap":39},[43,427,428,430,432],{"class":45,"line":46},[43,429,71],{"class":49},[43,431,54],{"class":53},[43,433,77],{"class":76},[43,435,436],{"class":45,"line":68},[43,437,84],{"emptyLinePlaceholder":83},[43,439,440,442,444,446,448],{"class":45,"line":80},[43,441,23],{"class":90},[43,443,93],{"class":49},[43,445,96],{"class":53},[43,447,99],{"class":76},[43,449,103],{"class":102},[43,451,452,454,456,458,460,462],{"class":45,"line":87},[43,453,220],{"class":109},[43,455,113],{"class":102},[43,457,225],{"class":57},[43,459,403],{"class":61},[43,461,225],{"class":57},[43,463,120],{"class":102},[14,465,466],{},"That causes an error because Python expected an indented block.",[14,468,469],{},"Good habits:",[125,471,472,475,478],{},[128,473,474],{},"use 4 spaces for each level of indentation",[128,476,477],{},"keep indentation consistent",[128,479,480],{},"do not mix tabs and spaces",[14,482,483,484,488,489,195],{},"To learn this rule in more detail, read ",[188,485,487],{"href":486},"\u002Flearn\u002Fpython-indentation-rules-and-why-they-matter\u002F","Python indentation rules and why they matter",". If indentation causes an error, see ",[188,490,492],{"href":491},"\u002Ferrors\u002Findentationerror-expected-an-indented-block-fix\u002F","IndentationError: expected an indented block",[26,494,496],{"id":495},"colons-start-a-code-block","Colons start a code block",[14,498,499,500,195],{},"In Python, lines that start a block often end with a colon ",[21,501,502],{},":",[14,504,505],{},"Common examples include:",[125,507,508,512,517,522,527],{},[128,509,510],{},[21,511,23],{},[128,513,514],{},[21,515,516],{},"for",[128,518,519],{},[21,520,521],{},"while",[128,523,524],{},[21,525,526],{},"def",[128,528,529],{},[21,530,531],{},"class",[14,533,534,535,502],{},"Example with ",[21,536,23],{},[34,538,540],{"className":36,"code":539,"language":38,"meta":39,"style":39},"score = 90\n\nif score > 50:\n    print(\"Pass\")\n",[21,541,542,552,556,570],{"__ignoreMap":39},[43,543,544,547,549],{"class":45,"line":46},[43,545,546],{"class":49},"score ",[43,548,54],{"class":53},[43,550,551],{"class":76}," 90\n",[43,553,554],{"class":45,"line":68},[43,555,84],{"emptyLinePlaceholder":83},[43,557,558,560,563,565,568],{"class":45,"line":80},[43,559,23],{"class":90},[43,561,562],{"class":49}," score ",[43,564,96],{"class":53},[43,566,567],{"class":76}," 50",[43,569,103],{"class":102},[43,571,572,574,576,578,581,583],{"class":45,"line":87},[43,573,110],{"class":109},[43,575,113],{"class":102},[43,577,225],{"class":57},[43,579,580],{"class":61},"Pass",[43,582,225],{"class":57},[43,584,120],{"class":102},[14,586,587],{},"The pattern is:",[589,590,591,594,597,600],"ol",{},[128,592,593],{},"Write the block-starting line",[128,595,596],{},"End it with a colon",[128,598,599],{},"Put the block on the next line",[128,601,602],{},"Indent the lines inside the block",[14,604,605],{},"Another short example:",[34,607,609],{"className":36,"code":608,"language":38,"meta":39,"style":39},"for i in range(3):\n    print(i)\n",[21,610,611,632],{"__ignoreMap":39},[43,612,613,615,618,621,624,626,629],{"class":45,"line":46},[43,614,516],{"class":90},[43,616,617],{"class":49}," i ",[43,619,620],{"class":90},"in",[43,622,623],{"class":109}," range",[43,625,113],{"class":102},[43,627,628],{"class":76},"3",[43,630,631],{"class":102},"):\n",[43,633,634,636,638,641],{"class":45,"line":68},[43,635,110],{"class":109},[43,637,113],{"class":102},[43,639,640],{"class":116},"i",[43,642,120],{"class":102},[14,644,645,646,195],{},"If you forget the colon, Python will raise an error. For that specific problem, see ",[188,647,649],{"href":648},"\u002Ferrors\u002Fsyntaxerror-missing-colon-fix\u002F","SyntaxError: missing colon",[26,651,653],{"id":652},"comments-are-ignored-by-python","Comments are ignored by Python",[14,655,656,657,195],{},"A comment starts with ",[21,658,659],{},"#",[14,661,363],{},[34,663,665],{"className":36,"code":664,"language":38,"meta":39,"style":39},"# This is a comment\nprint(\"Hello\")\n",[21,666,667,673],{"__ignoreMap":39},[43,668,669],{"class":45,"line":46},[43,670,672],{"class":671},"sutJx","# This is a comment\n",[43,674,675,677,679,681,683,685],{"class":45,"line":68},[43,676,220],{"class":109},[43,678,113],{"class":102},[43,680,225],{"class":57},[43,682,228],{"class":61},[43,684,225],{"class":57},[43,686,120],{"class":102},[14,688,689],{},"Comments are for humans reading the code. Python ignores them when the program runs.",[14,691,692],{},"You can use comments to:",[125,694,695,698,701],{},[128,696,697],{},"explain what code does",[128,699,700],{},"leave notes for yourself",[128,702,703],{},"make code easier to understand later",[14,705,363],{},[34,707,709],{"className":36,"code":708,"language":38,"meta":39,"style":39},"name = \"Sam\"  # store a name\nprint(name)\n",[21,710,711,726],{"__ignoreMap":39},[43,712,713,715,717,719,721,723],{"class":45,"line":46},[43,714,50],{"class":49},[43,716,54],{"class":53},[43,718,58],{"class":57},[43,720,62],{"class":61},[43,722,225],{"class":57},[43,724,725],{"class":671},"  # store a name\n",[43,727,728,730,732,734],{"class":45,"line":68},[43,729,220],{"class":109},[43,731,113],{"class":102},[43,733,117],{"class":116},[43,735,120],{"class":102},[14,737,738],{},"Python runs the code, but ignores the comment.",[14,740,741,742,195],{},"If you want to learn more, see ",[188,743,745],{"href":744},"\u002Flearn\u002Fpython-comments-explained-single-line-and-multi-line","Python comments explained: single-line and multi-line",[26,747,749],{"id":748},"case-sensitivity-in-python","Case sensitivity in Python",[14,751,752,753,756],{},"Python is ",[204,754,755],{},"case-sensitive",". That means uppercase and lowercase letters are treated as different.",[14,758,759],{},"These are three different names:",[125,761,762,766,771],{},[128,763,764],{},[21,765,117],{},[128,767,768],{},[21,769,770],{},"Name",[128,772,773],{},[21,774,775],{},"NAME",[14,777,363],{},[34,779,781],{"className":36,"code":780,"language":38,"meta":39,"style":39},"name = \"Sam\"\nprint(name)\n",[21,782,783,795],{"__ignoreMap":39},[43,784,785,787,789,791,793],{"class":45,"line":46},[43,786,50],{"class":49},[43,788,54],{"class":53},[43,790,58],{"class":57},[43,792,62],{"class":61},[43,794,65],{"class":57},[43,796,797,799,801,803],{"class":45,"line":68},[43,798,220],{"class":109},[43,800,113],{"class":102},[43,802,117],{"class":116},[43,804,120],{"class":102},[14,806,807],{},"This works.",[14,809,810],{},"But this does not:",[34,812,814],{"className":36,"code":813,"language":38,"meta":39,"style":39},"name = \"Sam\"\nprint(Name)\n",[21,815,816,828],{"__ignoreMap":39},[43,817,818,820,822,824,826],{"class":45,"line":46},[43,819,50],{"class":49},[43,821,54],{"class":53},[43,823,58],{"class":57},[43,825,62],{"class":61},[43,827,65],{"class":57},[43,829,830,832,834,836],{"class":45,"line":68},[43,831,220],{"class":109},[43,833,113],{"class":102},[43,835,770],{"class":116},[43,837,120],{"class":102},[14,839,840,841,843,844,195],{},"Why? Because ",[21,842,770],{}," is not the same as ",[21,845,117],{},[14,847,848,849,852,853,855,856,859],{},"Wrong capitalization can lead to bugs or errors such as ",[21,850,851],{},"NameError",". This also matters for Python keywords and built-in names. For example, ",[21,854,220],{}," is correct, but ",[21,857,858],{},"Print"," is not.",[14,861,862,863,195],{},"To learn more about special words in Python, see ",[188,864,866],{"href":865},"\u002Flearn\u002Fpython-keywords-explained-beginner-guide\u002F","Python keywords explained for beginners",[26,868,870],{"id":869},"strings-numbers-and-names","Strings, numbers, and names",[14,872,873],{},"In Python, text usually goes in quotes.",[14,875,363],{},[34,877,879],{"className":36,"code":878,"language":38,"meta":39,"style":39},"print(\"hello\")\n",[21,880,881],{"__ignoreMap":39},[43,882,883,885,887,889,892,894],{"class":45,"line":46},[43,884,220],{"class":109},[43,886,113],{"class":102},[43,888,225],{"class":57},[43,890,891],{"class":61},"hello",[43,893,225],{"class":57},[43,895,120],{"class":102},[14,897,410,898,901],{},[21,899,900],{},"\"hello\""," is a string.",[14,903,904,905,908],{},"Variable names do ",[204,906,907],{},"not"," use quotes:",[34,910,912],{"className":36,"code":911,"language":38,"meta":39,"style":39},"name = \"hello\"\nprint(name)\n",[21,913,914,926],{"__ignoreMap":39},[43,915,916,918,920,922,924],{"class":45,"line":46},[43,917,50],{"class":49},[43,919,54],{"class":53},[43,921,58],{"class":57},[43,923,891],{"class":61},[43,925,65],{"class":57},[43,927,928,930,932,934],{"class":45,"line":68},[43,929,220],{"class":109},[43,931,113],{"class":102},[43,933,117],{"class":116},[43,935,120],{"class":102},[14,937,938],{},"In this example:",[125,940,941,946],{},[128,942,943,945],{},[21,944,900],{}," is the text value",[128,947,948,950],{},[21,949,117],{}," is the variable name",[14,952,953],{},"Compare these two lines:",[34,955,957],{"className":36,"code":956,"language":38,"meta":39,"style":39},"print(\"name\")\nprint(name)\n",[21,958,959,973],{"__ignoreMap":39},[43,960,961,963,965,967,969,971],{"class":45,"line":46},[43,962,220],{"class":109},[43,964,113],{"class":102},[43,966,225],{"class":57},[43,968,117],{"class":61},[43,970,225],{"class":57},[43,972,120],{"class":102},[43,974,975,977,979,981],{"class":45,"line":68},[43,976,220],{"class":109},[43,978,113],{"class":102},[43,980,117],{"class":116},[43,982,120],{"class":102},[14,984,985],{},"They are different:",[125,987,988,996],{},[128,989,990,993,994],{},[21,991,992],{},"print(\"name\")"," prints the text ",[21,995,117],{},[128,997,998,1000,1001],{},[21,999,149],{}," prints the value stored in the variable ",[21,1002,117],{},[14,1004,1005],{},"Numbers also do not use quotes if you want them treated as numbers:",[34,1007,1009],{"className":36,"code":1008,"language":38,"meta":39,"style":39},"age = 12\nprint(age)\n",[21,1010,1011,1019],{"__ignoreMap":39},[43,1012,1013,1015,1017],{"class":45,"line":46},[43,1014,71],{"class":49},[43,1016,54],{"class":53},[43,1018,77],{"class":76},[43,1020,1021,1023,1025,1028],{"class":45,"line":68},[43,1022,220],{"class":109},[43,1024,113],{"class":102},[43,1026,1027],{"class":116},"age",[43,1029,120],{"class":102},[14,1031,1032,1033,1036],{},"If you write ",[21,1034,1035],{},"\"12\""," instead, that is text, not a number.",[26,1038,1040],{"id":1039},"a-small-valid-program","A small valid program",[14,1042,1043],{},"Here is a short program that combines several basic syntax rules:",[34,1045,1047],{"className":36,"code":1046,"language":38,"meta":39,"style":39},"name = \"Lina\"\nage = 15\n\nprint(\"Checking age...\")\n\nif age >= 13:\n    print(name)\n    print(\"Teenager\")\n",[21,1048,1049,1062,1071,1075,1090,1094,1109,1120],{"__ignoreMap":39},[43,1050,1051,1053,1055,1057,1060],{"class":45,"line":46},[43,1052,50],{"class":49},[43,1054,54],{"class":53},[43,1056,58],{"class":57},[43,1058,1059],{"class":61},"Lina",[43,1061,65],{"class":57},[43,1063,1064,1066,1068],{"class":45,"line":68},[43,1065,71],{"class":49},[43,1067,54],{"class":53},[43,1069,1070],{"class":76}," 15\n",[43,1072,1073],{"class":45,"line":80},[43,1074,84],{"emptyLinePlaceholder":83},[43,1076,1077,1079,1081,1083,1086,1088],{"class":45,"line":87},[43,1078,220],{"class":109},[43,1080,113],{"class":102},[43,1082,225],{"class":57},[43,1084,1085],{"class":61},"Checking age...",[43,1087,225],{"class":57},[43,1089,120],{"class":102},[43,1091,1092],{"class":45,"line":106},[43,1093,84],{"emptyLinePlaceholder":83},[43,1095,1097,1099,1101,1104,1107],{"class":45,"line":1096},6,[43,1098,23],{"class":90},[43,1100,93],{"class":49},[43,1102,1103],{"class":53},">=",[43,1105,1106],{"class":76}," 13",[43,1108,103],{"class":102},[43,1110,1112,1114,1116,1118],{"class":45,"line":1111},7,[43,1113,110],{"class":109},[43,1115,113],{"class":102},[43,1117,117],{"class":116},[43,1119,120],{"class":102},[43,1121,1123,1125,1127,1129,1132,1134],{"class":45,"line":1122},8,[43,1124,110],{"class":109},[43,1126,113],{"class":102},[43,1128,225],{"class":57},[43,1130,1131],{"class":61},"Teenager",[43,1133,225],{"class":57},[43,1135,120],{"class":102},[14,1137,1138],{},"What this program uses:",[125,1140,1141,1149,1158,1164,1170],{},[128,1142,1143,1144,1146,1147],{},"variables: ",[21,1145,117],{}," and ",[21,1148,1027],{},[128,1150,1151,1152,1146,1155],{},"strings in quotes: ",[21,1153,1154],{},"\"Lina\"",[21,1156,1157],{},"\"Checking age...\"",[128,1159,1160,1161],{},"a normal statement: ",[21,1162,1163],{},"print(...)",[128,1165,1166,1167,1169],{},"an ",[21,1168,23],{}," statement ending with a colon",[128,1171,1172,1173,153],{},"indentation inside the ",[21,1174,23],{},[14,1176,1177],{},"Expected output:",[34,1179,1181],{"className":36,"code":1180,"language":38,"meta":39,"style":39},"Checking age...\nLina\nTeenager\n",[21,1182,1183,1192,1197],{"__ignoreMap":39},[43,1184,1185,1188],{"class":45,"line":46},[43,1186,1187],{"class":49},"Checking age",[43,1189,1191],{"class":1190},"s_hVV","...\n",[43,1193,1194],{"class":45,"line":68},[43,1195,1196],{"class":49},"Lina\n",[43,1198,1199],{"class":45,"line":80},[43,1200,1201],{"class":49},"Teenager\n",[14,1203,1204],{},"You can use this as a quick syntax checklist:",[125,1206,1207,1209,1212,1215,1220,1223],{},[128,1208,344],{},[128,1210,1211],{},"quotes around text",[128,1213,1214],{},"no quotes around variable names",[128,1216,1217,1218],{},"colon after ",[21,1219,23],{},[128,1221,1222],{},"indentation inside the block",[128,1224,1225],{},"correct capitalization",[26,1227,1229],{"id":1228},"common-syntax-problems-beginners-make","Common syntax problems beginners make",[14,1231,1232],{},"These are some of the most common beginner mistakes:",[125,1234,1235,1248,1251,1254,1257,1267],{},[128,1236,1237,1238,1240,1241,1240,1243,1245,1246],{},"Missing the colon after ",[21,1239,23],{},", ",[21,1242,516],{},[21,1244,521],{},", or ",[21,1247,526],{},[128,1249,1250],{},"Forgetting to indent code after a colon",[128,1252,1253],{},"Mixing tabs and spaces",[128,1255,1256],{},"Leaving a quote, bracket, or parenthesis unclosed",[128,1258,1259,1260,1240,1262,1245,1264],{},"Using the wrong capitalization in names like ",[21,1261,220],{},[21,1263,117],{},[21,1265,1266],{},"True",[128,1268,1269],{},"Writing text without quotes when a string is intended",[14,1271,1272],{},"Examples of common problems:",[1274,1275,1277],"h3",{"id":1276},"missing-colon","Missing colon",[34,1279,1281],{"className":36,"code":1280,"language":38,"meta":39,"style":39},"age = 12\n\nif age > 10\n    print(\"OK\")\n",[21,1282,1283,1291,1295,1306],{"__ignoreMap":39},[43,1284,1285,1287,1289],{"class":45,"line":46},[43,1286,71],{"class":49},[43,1288,54],{"class":53},[43,1290,77],{"class":76},[43,1292,1293],{"class":45,"line":68},[43,1294,84],{"emptyLinePlaceholder":83},[43,1296,1297,1299,1301,1303],{"class":45,"line":80},[43,1298,23],{"class":90},[43,1300,93],{"class":49},[43,1302,96],{"class":53},[43,1304,1305],{"class":76}," 10\n",[43,1307,1308,1310,1312,1314,1317,1319],{"class":45,"line":87},[43,1309,110],{"class":109},[43,1311,113],{"class":102},[43,1313,225],{"class":57},[43,1315,1316],{"class":61},"OK",[43,1318,225],{"class":57},[43,1320,120],{"class":102},[14,1322,1323],{},"Problem:",[125,1325,1326],{},[128,1327,1328,1331,1332],{},[21,1329,1330],{},"if age > 10"," should end with ",[21,1333,502],{},[14,1335,1336],{},"Fixed version:",[34,1338,1340],{"className":36,"code":1339,"language":38,"meta":39,"style":39},"age = 12\n\nif age > 10:\n    print(\"OK\")\n",[21,1341,1342,1350,1354,1366],{"__ignoreMap":39},[43,1343,1344,1346,1348],{"class":45,"line":46},[43,1345,71],{"class":49},[43,1347,54],{"class":53},[43,1349,77],{"class":76},[43,1351,1352],{"class":45,"line":68},[43,1353,84],{"emptyLinePlaceholder":83},[43,1355,1356,1358,1360,1362,1364],{"class":45,"line":80},[43,1357,23],{"class":90},[43,1359,93],{"class":49},[43,1361,96],{"class":53},[43,1363,99],{"class":76},[43,1365,103],{"class":102},[43,1367,1368,1370,1372,1374,1376,1378],{"class":45,"line":87},[43,1369,110],{"class":109},[43,1371,113],{"class":102},[43,1373,225],{"class":57},[43,1375,1316],{"class":61},[43,1377,225],{"class":57},[43,1379,120],{"class":102},[1274,1381,1383],{"id":1382},"missing-indentation","Missing indentation",[34,1385,1387],{"className":36,"code":1386,"language":38,"meta":39,"style":39},"age = 12\n\nif age > 10:\nprint(\"OK\")\n",[21,1388,1389,1397,1401,1413],{"__ignoreMap":39},[43,1390,1391,1393,1395],{"class":45,"line":46},[43,1392,71],{"class":49},[43,1394,54],{"class":53},[43,1396,77],{"class":76},[43,1398,1399],{"class":45,"line":68},[43,1400,84],{"emptyLinePlaceholder":83},[43,1402,1403,1405,1407,1409,1411],{"class":45,"line":80},[43,1404,23],{"class":90},[43,1406,93],{"class":49},[43,1408,96],{"class":53},[43,1410,99],{"class":76},[43,1412,103],{"class":102},[43,1414,1415,1417,1419,1421,1423,1425],{"class":45,"line":87},[43,1416,220],{"class":109},[43,1418,113],{"class":102},[43,1420,225],{"class":57},[43,1422,1316],{"class":61},[43,1424,225],{"class":57},[43,1426,120],{"class":102},[14,1428,1323],{},[125,1430,1431],{},[128,1432,1433,1434,1436],{},"the ",[21,1435,220],{}," line must be indented",[14,1438,1336],{},[34,1440,1441],{"className":36,"code":1339,"language":38,"meta":39,"style":39},[21,1442,1443,1451,1455,1467],{"__ignoreMap":39},[43,1444,1445,1447,1449],{"class":45,"line":46},[43,1446,71],{"class":49},[43,1448,54],{"class":53},[43,1450,77],{"class":76},[43,1452,1453],{"class":45,"line":68},[43,1454,84],{"emptyLinePlaceholder":83},[43,1456,1457,1459,1461,1463,1465],{"class":45,"line":80},[43,1458,23],{"class":90},[43,1460,93],{"class":49},[43,1462,96],{"class":53},[43,1464,99],{"class":76},[43,1466,103],{"class":102},[43,1468,1469,1471,1473,1475,1477,1479],{"class":45,"line":87},[43,1470,110],{"class":109},[43,1472,113],{"class":102},[43,1474,225],{"class":57},[43,1476,1316],{"class":61},[43,1478,225],{"class":57},[43,1480,120],{"class":102},[1274,1482,1484],{"id":1483},"unclosed-quote","Unclosed quote",[34,1486,1488],{"className":36,"code":1487,"language":38,"meta":39,"style":39},"print(\"Hello)\n",[21,1489,1490],{"__ignoreMap":39},[43,1491,1492,1494,1496,1498],{"class":45,"line":46},[43,1493,220],{"class":109},[43,1495,113],{"class":102},[43,1497,225],{"class":57},[43,1499,1500],{"class":61},"Hello)\n",[14,1502,1323],{},[125,1504,1505],{},[128,1506,1507,1508,1510,1511],{},"the string starts with ",[21,1509,225],{}," but does not close with ",[21,1512,225],{},[14,1514,1336],{},[34,1516,1518],{"className":36,"code":1517,"language":38,"meta":39,"style":39},"print(\"Hello\")\n",[21,1519,1520],{"__ignoreMap":39},[43,1521,1522,1524,1526,1528,1530,1532],{"class":45,"line":46},[43,1523,220],{"class":109},[43,1525,113],{"class":102},[43,1527,225],{"class":57},[43,1529,228],{"class":61},[43,1531,225],{"class":57},[43,1533,120],{"class":102},[1274,1535,1537],{"id":1536},"wrong-capitalization","Wrong capitalization",[34,1539,1541],{"className":36,"code":1540,"language":38,"meta":39,"style":39},"Print(\"Hello\")\n",[21,1542,1543],{"__ignoreMap":39},[43,1544,1545,1547,1549,1551,1553,1555],{"class":45,"line":46},[43,1546,858],{"class":116},[43,1548,113],{"class":102},[43,1550,225],{"class":57},[43,1552,228],{"class":61},[43,1554,225],{"class":57},[43,1556,120],{"class":102},[14,1558,1323],{},[125,1560,1561],{},[128,1562,1563,843,1565],{},[21,1564,858],{},[21,1566,220],{},[14,1568,1336],{},[34,1570,1571],{"className":36,"code":1517,"language":38,"meta":39,"style":39},[21,1572,1573],{"__ignoreMap":39},[43,1574,1575,1577,1579,1581,1583,1585],{"class":45,"line":46},[43,1576,220],{"class":109},[43,1578,113],{"class":102},[43,1580,225],{"class":57},[43,1582,228],{"class":61},[43,1584,225],{"class":57},[43,1586,120],{"class":102},[14,1588,1589],{},"If you are not sure what is wrong, these simple commands can help while learning:",[34,1591,1595],{"className":1592,"code":1593,"language":1594,"meta":39,"style":39},"language-bash shiki shiki-themes material-theme-lighter github-light github-dark","python your_file.py\n","bash",[21,1596,1597],{"__ignoreMap":39},[43,1598,1599,1602],{"class":45,"line":46},[43,1600,38],{"class":1601},"sbgvK",[43,1603,1604],{"class":61}," your_file.py\n",[14,1606,1607],{},"Runs your Python file so you can see the error message.",[34,1609,1611],{"className":36,"code":1610,"language":38,"meta":39,"style":39},"print(\"debug\")\n",[21,1612,1613],{"__ignoreMap":39},[43,1614,1615,1617,1619,1621,1624,1626],{"class":45,"line":46},[43,1616,220],{"class":109},[43,1618,113],{"class":102},[43,1620,225],{"class":57},[43,1622,1623],{"class":61},"debug",[43,1625,225],{"class":57},[43,1627,120],{"class":102},[14,1629,1630],{},"A quick way to check whether a line or block runs.",[34,1632,1634],{"className":36,"code":1633,"language":38,"meta":39,"style":39},"help(print)\n",[21,1635,1636],{"__ignoreMap":39},[43,1637,1638,1641,1643,1645],{"class":45,"line":46},[43,1639,1640],{"class":109},"help",[43,1642,113],{"class":102},[43,1644,220],{"class":109},[43,1646,120],{"class":102},[14,1648,1649,1650,1652],{},"Shows help for the ",[21,1651,220],{}," function.",[34,1654,1656],{"className":36,"code":1655,"language":38,"meta":39,"style":39},"type(\"hello\")\n",[21,1657,1658],{"__ignoreMap":39},[43,1659,1660,1664,1666,1668,1670,1672],{"class":45,"line":46},[43,1661,1663],{"class":1662},"sZMiF","type",[43,1665,113],{"class":102},[43,1667,225],{"class":57},[43,1669,891],{"class":61},[43,1671,225],{"class":57},[43,1673,120],{"class":102},[14,1675,1676,1677,195],{},"Shows the type of a value. In this case, it returns ",[21,1678,1679],{},"str",[26,1681,1683],{"id":1682},"faq","FAQ",[1274,1685,1687],{"id":1686},"what-is-python-syntax-in-simple-words","What is Python syntax in simple words?",[14,1689,1690],{},"Python syntax is the set of writing rules Python uses to understand your code.",[1274,1692,1694],{"id":1693},"why-does-indentation-matter-in-python","Why does indentation matter in Python?",[14,1696,1697,1698,1700],{},"Indentation shows which lines belong inside a block, such as an ",[21,1699,23],{}," statement or loop.",[1274,1702,1704],{"id":1703},"do-i-always-need-a-colon-in-python","Do I always need a colon in Python?",[14,1706,1707,1708,1240,1710,1240,1712,1714,1715,195],{},"No. You usually need a colon after statements that start a block, such as ",[21,1709,23],{},[21,1711,516],{},[21,1713,521],{},", and ",[21,1716,526],{},[1274,1718,1720],{"id":1719},"is-python-case-sensitive","Is Python case-sensitive?",[14,1722,1723],{},"Yes. Lowercase and uppercase letters are treated as different.",[1274,1725,1727],{"id":1726},"are-comments-part-of-python-syntax","Are comments part of Python syntax?",[14,1729,1730],{},"Yes, but Python ignores comments when running the code.",[26,1732,1734],{"id":1733},"see-also","See also",[125,1736,1737,1741,1745,1750,1754,1758,1762],{},[128,1738,1739],{},[188,1740,487],{"href":486},[128,1742,1743],{},[188,1744,745],{"href":744},[128,1746,1747],{},[188,1748,1749],{"href":272},"Understanding Python statements and expressions",[128,1751,1752],{},[188,1753,866],{"href":865},[128,1755,1756],{},[188,1757,194],{"href":190},[128,1759,1760],{},[188,1761,492],{"href":491},[128,1763,1764],{},[188,1765,649],{"href":648},[14,1767,1768,1769,1771],{},"Once these basic writing rules make sense, the next good topics are indentation, comments, and statements. After that, move on to variables and simple ",[21,1770,23],{}," statements.",[1773,1774,1775],"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 .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 .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 .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 .sutJx, html code.shiki .sutJx{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#6A737D;--shiki-default-font-style:inherit;--shiki-dark:#6A737D;--shiki-dark-font-style:inherit}html pre.shiki code .s_hVV, html code.shiki .s_hVV{--shiki-light:#90A4AE;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sbgvK, html code.shiki .sbgvK{--shiki-light:#E2931D;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":39,"searchDepth":68,"depth":68,"links":1777},[1778,1779,1780,1781,1782,1783,1784,1785,1786,1787,1788,1794,1801],{"id":28,"depth":68,"text":29},{"id":168,"depth":68,"text":169},{"id":198,"depth":68,"text":199},{"id":276,"depth":68,"text":277},{"id":353,"depth":68,"text":354},{"id":495,"depth":68,"text":496},{"id":652,"depth":68,"text":653},{"id":748,"depth":68,"text":749},{"id":869,"depth":68,"text":870},{"id":1039,"depth":68,"text":1040},{"id":1228,"depth":68,"text":1229,"children":1789},[1790,1791,1792,1793],{"id":1276,"depth":80,"text":1277},{"id":1382,"depth":80,"text":1383},{"id":1483,"depth":80,"text":1484},{"id":1536,"depth":80,"text":1537},{"id":1682,"depth":68,"text":1683,"children":1795},[1796,1797,1798,1799,1800],{"id":1686,"depth":80,"text":1687},{"id":1693,"depth":80,"text":1694},{"id":1703,"depth":80,"text":1704},{"id":1719,"depth":80,"text":1720},{"id":1726,"depth":80,"text":1727},{"id":1733,"depth":68,"text":1734},"Master python syntax basics explained in our comprehensive Python beginner guide.","md",{},"\u002Flearn\u002Fpython-syntax-basics-explained",{"title":5,"description":1802},"learn\u002Fpython-syntax-basics-explained","rp-07k1USQd1xOcKADYoVkEydN9QZjYzP5Zw9vkU2s8",1777585504452]