[{"data":1,"prerenderedAt":1689},["ShallowReactive",2],{"doc-\u002Flearn\u002Funderstanding-python-statements-and-expressions":3},{"id":4,"title":5,"body":6,"description":1682,"extension":1683,"meta":1684,"navigation":101,"path":1685,"seo":1686,"stem":1687,"__hash__":1688},"content\u002Flearn\u002Funderstanding-python-statements-and-expressions.md","Understanding Python Statements and Expressions",{"type":7,"value":8,"toc":1637},"minimark",[9,13,26,32,38,41,46,122,129,133,149,153,156,159,187,190,204,211,216,275,278,307,316,320,323,326,349,353,410,413,454,457,467,471,474,488,491,546,549,576,580,583,587,606,619,623,639,651,655,689,705,712,716,747,765,769,772,776,807,825,828,836,840,887,904,908,952,970,978,982,985,989,992,995,1025,1029,1032,1034,1062,1066,1069,1096,1100,1103,1123,1127,1130,1133,1150,1153,1161,1164,1168,1171,1175,1178,1181,1199,1210,1214,1217,1234,1247,1255,1279,1285,1296,1300,1327,1338,1342,1345,1445,1448,1493,1496,1526,1533,1537,1544,1553,1557,1560,1562,1579,1584,1588,1594,1598,1601,1605,1630,1633],[10,11,5],"h1",{"id":12},"understanding-python-statements-and-expressions",[14,15,16,17,21,22,25],"p",{},"When you start learning Python, you will see terms like ",[18,19,20],"strong",{},"statement"," and ",[18,23,24],{},"expression",". These words sound technical, but the idea is simple.",[14,27,28,29,31],{},"A ",[18,30,20],{}," is code that tells Python to do something.",[14,33,34,35,37],{},"An ",[18,36,24],{}," is code that Python evaluates to a value.",[14,39,40],{},"You will often see both working together in the same line of code. Once you understand that, beginner code becomes much easier to read.",[42,43,45],"h2",{"id":44},"quick-rule","Quick rule",[47,48,53],"pre",{"className":49,"code":50,"language":51,"meta":52,"style":52},"language-python shiki shiki-themes material-theme-lighter github-light github-dark","x = 10\nprint(x + 5)\n\n# x = 10 is a statement\n# x + 5 is an expression\n# print(x + 5) is a statement that contains an expression\n","python","",[54,55,56,73,96,103,110,116],"code",{"__ignoreMap":52},[57,58,61,65,69],"span",{"class":59,"line":60},"line",1,[57,62,64],{"class":63},"su5hD","x ",[57,66,68],{"class":67},"smGrS","=",[57,70,72],{"class":71},"srdBf"," 10\n",[57,74,76,80,84,87,90,93],{"class":59,"line":75},2,[57,77,79],{"class":78},"sptTA","print",[57,81,83],{"class":82},"sP7_E","(",[57,85,64],{"class":86},"slqww",[57,88,89],{"class":67},"+",[57,91,92],{"class":71}," 5",[57,94,95],{"class":82},")\n",[57,97,99],{"class":59,"line":98},3,[57,100,102],{"emptyLinePlaceholder":101},true,"\n",[57,104,106],{"class":59,"line":105},4,[57,107,109],{"class":108},"sutJx","# x = 10 is a statement\n",[57,111,113],{"class":59,"line":112},5,[57,114,115],{"class":108},"# x + 5 is an expression\n",[57,117,119],{"class":59,"line":118},6,[57,120,121],{"class":108},"# print(x + 5) is a statement that contains an expression\n",[14,123,124,125,128],{},"Use this simple rule: ",[18,126,127],{},"an expression produces a value, while a statement performs an action",".",[42,130,132],{"id":131},"what-this-page-helps-you-understand","What this page helps you understand",[134,135,136,140,143,146],"ul",{},[137,138,139],"li",{},"A statement is a line of code that does something",[137,141,142],{},"An expression is code that produces a value",[137,144,145],{},"Many Python lines contain both a statement and an expression",[137,147,148],{},"You do not need advanced theory to use this idea in practice",[42,150,152],{"id":151},"what-is-a-statement-in-python","What is a statement in Python?",[14,154,155],{},"A statement tells Python to perform an action.",[14,157,158],{},"Common examples of statements include:",[134,160,161,164,170,176,181],{},[137,162,163],{},"variable assignment",[137,165,166,169],{},[54,167,168],{},"if"," statements",[137,171,172,175],{},[54,173,174],{},"for"," loops",[137,177,178,169],{},[54,179,180],{},"import",[137,182,183,184],{},"function definitions with ",[54,185,186],{},"def",[14,188,189],{},"Statements often:",[134,191,192,195,198,201],{},[137,193,194],{},"control the flow of a program",[137,196,197],{},"create or change variables",[137,199,200],{},"run blocks of code",[137,202,203],{},"perform actions",[14,205,206,207,210],{},"A statement does ",[18,208,209],{},"not"," need to return a value.",[212,213,215],"h3",{"id":214},"examples-of-statements","Examples of statements",[47,217,219],{"className":49,"code":218,"language":51,"meta":52,"style":52},"x = 10\nimport math\n\nif x > 5:\n    print(\"x is greater than 5\")\n",[54,220,221,229,237,241,256],{"__ignoreMap":52},[57,222,223,225,227],{"class":59,"line":60},[57,224,64],{"class":63},[57,226,68],{"class":67},[57,228,72],{"class":71},[57,230,231,234],{"class":59,"line":75},[57,232,180],{"class":233},"sVHd0",[57,235,236],{"class":63}," math\n",[57,238,239],{"class":59,"line":98},[57,240,102],{"emptyLinePlaceholder":101},[57,242,243,245,248,251,253],{"class":59,"line":105},[57,244,168],{"class":233},[57,246,247],{"class":63}," x ",[57,249,250],{"class":67},">",[57,252,92],{"class":71},[57,254,255],{"class":82},":\n",[57,257,258,261,263,267,271,273],{"class":59,"line":112},[57,259,260],{"class":78},"    print",[57,262,83],{"class":82},[57,264,266],{"class":265},"sjJ54","\"",[57,268,270],{"class":269},"s_sjI","x is greater than 5",[57,272,266],{"class":265},[57,274,95],{"class":82},[14,276,277],{},"In this example:",[134,279,280,286,292,301],{},[137,281,282,285],{},[54,283,284],{},"x = 10"," is an assignment statement",[137,287,288,291],{},[54,289,290],{},"import math"," is an import statement",[137,293,294,297,298,300],{},[54,295,296],{},"if x > 5:"," starts an ",[54,299,168],{}," statement",[137,302,303,306],{},[54,304,305],{},"print(\"x is greater than 5\")"," is commonly treated as a statement in beginner code because it performs an action",[14,308,309,310,315],{},"If you are still learning Python basics, it helps to first understand ",[311,312,314],"a",{"href":313},"\u002Flearn\u002Fpython-syntax-basics-explained\u002F","Python syntax basics"," because statements are a big part of Python syntax.",[42,317,319],{"id":318},"what-is-an-expression-in-python","What is an expression in Python?",[14,321,322],{},"An expression is code that Python can evaluate to a value.",[14,324,325],{},"That value might be:",[134,327,328,331,334,343,346],{},[137,329,330],{},"a number",[137,332,333],{},"a string",[137,335,336,339,340],{},[54,337,338],{},"True"," or ",[54,341,342],{},"False",[137,344,345],{},"a list",[137,347,348],{},"the result of a function call",[212,350,352],{"id":351},"examples-of-expressions","Examples of expressions",[47,354,356],{"className":49,"code":355,"language":51,"meta":52,"style":52},"5\n\"hello\"\nx + 1\nlen(\"Sam\")\nage > 18\n",[54,357,358,363,375,384,400],{"__ignoreMap":52},[57,359,360],{"class":59,"line":60},[57,361,362],{"class":71},"5\n",[57,364,365,368,372],{"class":59,"line":75},[57,366,266],{"class":367},"s2W-s",[57,369,371],{"class":370},"sithA","hello",[57,373,374],{"class":367},"\"\n",[57,376,377,379,381],{"class":59,"line":98},[57,378,64],{"class":63},[57,380,89],{"class":67},[57,382,383],{"class":71}," 1\n",[57,385,386,389,391,393,396,398],{"class":59,"line":105},[57,387,388],{"class":78},"len",[57,390,83],{"class":82},[57,392,266],{"class":265},[57,394,395],{"class":269},"Sam",[57,397,266],{"class":265},[57,399,95],{"class":82},[57,401,402,405,407],{"class":59,"line":112},[57,403,404],{"class":63},"age ",[57,406,250],{"class":67},[57,408,409],{"class":71}," 18\n",[14,411,412],{},"Each of these produces a value:",[134,414,415,423,429,435,444],{},[137,416,417,420,421],{},[54,418,419],{},"5"," produces the value ",[54,422,419],{},[137,424,425,428],{},[54,426,427],{},"\"hello\""," produces a string",[137,430,431,434],{},[54,432,433],{},"x + 1"," produces a calculated result",[137,436,437,440,441],{},[54,438,439],{},"len(\"Sam\")"," produces ",[54,442,443],{},"3",[137,445,446,449,450,339,452],{},[54,447,448],{},"age > 18"," produces either ",[54,451,338],{},[54,453,342],{},[14,455,456],{},"Expressions can be simple or built from smaller parts.",[14,458,459,460,462,463,128],{},"You will often see expressions on the right side of ",[54,461,68],{}," in ",[311,464,466],{"href":465},"\u002Flearn\u002Fpython-variables-explained-for-beginners\u002F","Python variables",[42,468,470],{"id":469},"statement-vs-expression-the-simple-difference","Statement vs expression: the simple difference",[14,472,473],{},"The easiest way to remember the difference is this:",[134,475,476,482],{},[137,477,478,481],{},[18,479,480],{},"Expression"," = produces a value",[137,483,484,487],{},[18,485,486],{},"Statement"," = performs an action",[14,489,490],{},"Here is a simple example:",[47,492,494],{"className":49,"code":493,"language":51,"meta":52,"style":52},"price = 20\ntax = 5\ntotal = price + tax\n\nprint(total)\n",[54,495,496,506,516,531,535],{"__ignoreMap":52},[57,497,498,501,503],{"class":59,"line":60},[57,499,500],{"class":63},"price ",[57,502,68],{"class":67},[57,504,505],{"class":71}," 20\n",[57,507,508,511,513],{"class":59,"line":75},[57,509,510],{"class":63},"tax ",[57,512,68],{"class":67},[57,514,515],{"class":71}," 5\n",[57,517,518,521,523,526,528],{"class":59,"line":98},[57,519,520],{"class":63},"total ",[57,522,68],{"class":67},[57,524,525],{"class":63}," price ",[57,527,89],{"class":67},[57,529,530],{"class":63}," tax\n",[57,532,533],{"class":59,"line":105},[57,534,102],{"emptyLinePlaceholder":101},[57,536,537,539,541,544],{"class":59,"line":112},[57,538,79],{"class":78},[57,540,83],{"class":82},[57,542,543],{"class":86},"total",[57,545,95],{"class":82},[14,547,548],{},"What is happening here?",[134,550,551,556,562,568],{},[137,552,553,285],{},[54,554,555],{},"total = price + tax",[137,557,558,561],{},[54,559,560],{},"price + tax"," is an expression",[137,563,564,567],{},[54,565,566],{},"print(total)"," performs an action, so beginners usually treat it as a statement",[137,569,570,572,573,575],{},[54,571,543],{}," inside ",[54,574,566],{}," is an expression because Python evaluates it to its current value",[42,577,579],{"id":578},"common-examples-beginners-see","Common examples beginners see",[14,581,582],{},"These are patterns you will see often in real code.",[212,584,586],{"id":585},"assignment","Assignment",[47,588,590],{"className":49,"code":589,"language":51,"meta":52,"style":52},"name = \"Sam\"\n",[54,591,592],{"__ignoreMap":52},[57,593,594,597,599,602,604],{"class":59,"line":60},[57,595,596],{"class":63},"name ",[57,598,68],{"class":67},[57,600,601],{"class":265}," \"",[57,603,395],{"class":269},[57,605,374],{"class":265},[134,607,608,614],{},[137,609,610,613],{},[54,611,612],{},"name = \"Sam\""," is a statement",[137,615,616,561],{},[54,617,618],{},"\"Sam\"",[212,620,622],{"id":621},"printing-a-value","Printing a value",[47,624,626],{"className":49,"code":625,"language":51,"meta":52,"style":52},"print(name)\n",[54,627,628],{"__ignoreMap":52},[57,629,630,632,634,637],{"class":59,"line":60},[57,631,79],{"class":78},[57,633,83],{"class":82},[57,635,636],{"class":86},"name",[57,638,95],{"class":82},[134,640,641,647],{},[137,642,643,646],{},[54,644,645],{},"print(name)"," is usually treated as a statement in beginner explanations",[137,648,649,561],{},[54,650,636],{},[212,652,654],{"id":653},"condition-in-an-if-statement","Condition in an if statement",[47,656,658],{"className":49,"code":657,"language":51,"meta":52,"style":52},"if score > 50:\n    print(\"Pass\")\n",[54,659,660,674],{"__ignoreMap":52},[57,661,662,664,667,669,672],{"class":59,"line":60},[57,663,168],{"class":233},[57,665,666],{"class":63}," score ",[57,668,250],{"class":67},[57,670,671],{"class":71}," 50",[57,673,255],{"class":82},[57,675,676,678,680,682,685,687],{"class":59,"line":75},[57,677,260],{"class":78},[57,679,83],{"class":82},[57,681,266],{"class":265},[57,683,684],{"class":269},"Pass",[57,686,266],{"class":265},[57,688,95],{"class":82},[134,690,691,699],{},[137,692,693,696,697,300],{},[54,694,695],{},"if score > 50:"," is an ",[54,698,168],{},[137,700,701,704],{},[54,702,703],{},"score > 50"," is the condition expression",[14,706,707,708,128],{},"If you want to go deeper into conditions, see ",[311,709,711],{"href":710},"\u002Flearn\u002Fpython-if-statements-explained\u002F","Python if statements explained",[212,713,715],{"id":714},"loop","Loop",[47,717,719],{"className":49,"code":718,"language":51,"meta":52,"style":52},"for item in items:\n    print(item)\n",[54,720,721,736],{"__ignoreMap":52},[57,722,723,725,728,731,734],{"class":59,"line":60},[57,724,174],{"class":233},[57,726,727],{"class":63}," item ",[57,729,730],{"class":233},"in",[57,732,733],{"class":63}," items",[57,735,255],{"class":82},[57,737,738,740,742,745],{"class":59,"line":75},[57,739,260],{"class":78},[57,741,83],{"class":82},[57,743,744],{"class":86},"item",[57,746,95],{"class":82},[134,748,749,757],{},[137,750,751,754,755,300],{},[54,752,753],{},"for item in items:"," is a ",[54,756,174],{},[137,758,759,21,761,764],{},[54,760,744],{},[54,762,763],{},"items"," are names used in the statement",[42,766,768],{"id":767},"how-statements-and-expressions-work-together","How statements and expressions work together",[14,770,771],{},"Statements and expressions are not separate worlds. In real Python code, statements often contain expressions.",[212,773,775],{"id":774},"assignment-uses-an-expression","Assignment uses an expression",[47,777,779],{"className":49,"code":778,"language":51,"meta":52,"style":52},"x = 2 + 3\nprint(x)\n",[54,780,781,796],{"__ignoreMap":52},[57,782,783,785,787,790,793],{"class":59,"line":60},[57,784,64],{"class":63},[57,786,68],{"class":67},[57,788,789],{"class":71}," 2",[57,791,792],{"class":67}," +",[57,794,795],{"class":71}," 3\n",[57,797,798,800,802,805],{"class":59,"line":75},[57,799,79],{"class":78},[57,801,83],{"class":82},[57,803,804],{"class":86},"x",[57,806,95],{"class":82},[134,808,809,814,820],{},[137,810,811,613],{},[54,812,813],{},"x = 2 + 3",[137,815,816,819],{},[54,817,818],{},"2 + 3"," is the expression",[137,821,822,823],{},"Python evaluates the expression first, then assigns the result to ",[54,824,804],{},[14,826,827],{},"Output:",[47,829,830],{"className":49,"code":362,"language":51,"meta":52,"style":52},[54,831,832],{"__ignoreMap":52},[57,833,834],{"class":59,"line":60},[57,835,362],{"class":71},[212,837,839],{"id":838},"if-statements-use-expressions-as-conditions","If statements use expressions as conditions",[47,841,843],{"className":49,"code":842,"language":51,"meta":52,"style":52},"age = 20\n\nif age >= 18:\n    print(\"Adult\")\n",[54,844,845,853,857,872],{"__ignoreMap":52},[57,846,847,849,851],{"class":59,"line":60},[57,848,404],{"class":63},[57,850,68],{"class":67},[57,852,505],{"class":71},[57,854,855],{"class":59,"line":75},[57,856,102],{"emptyLinePlaceholder":101},[57,858,859,861,864,867,870],{"class":59,"line":98},[57,860,168],{"class":233},[57,862,863],{"class":63}," age ",[57,865,866],{"class":67},">=",[57,868,869],{"class":71}," 18",[57,871,255],{"class":82},[57,873,874,876,878,880,883,885],{"class":59,"line":105},[57,875,260],{"class":78},[57,877,83],{"class":82},[57,879,266],{"class":265},[57,881,882],{"class":269},"Adult",[57,884,266],{"class":265},[57,886,95],{"class":82},[134,888,889,894],{},[137,890,891,613],{},[54,892,893],{},"if age >= 18:",[137,895,896,899,900,339,902],{},[54,897,898],{},"age >= 18"," is an expression that becomes ",[54,901,338],{},[54,903,342],{},[212,905,907],{"id":906},"function-calls-can-produce-values","Function calls can produce values",[47,909,911],{"className":49,"code":910,"language":51,"meta":52,"style":52},"name = \"hello\"\nlength = len(name)\nprint(length)\n",[54,912,913,925,941],{"__ignoreMap":52},[57,914,915,917,919,921,923],{"class":59,"line":60},[57,916,596],{"class":63},[57,918,68],{"class":67},[57,920,601],{"class":265},[57,922,371],{"class":269},[57,924,374],{"class":265},[57,926,927,930,932,935,937,939],{"class":59,"line":75},[57,928,929],{"class":63},"length ",[57,931,68],{"class":67},[57,933,934],{"class":78}," len",[57,936,83],{"class":82},[57,938,636],{"class":86},[57,940,95],{"class":82},[57,942,943,945,947,950],{"class":59,"line":98},[57,944,79],{"class":78},[57,946,83],{"class":82},[57,948,949],{"class":86},"length",[57,951,95],{"class":82},[134,953,954,959,965],{},[137,955,956,613],{},[54,957,958],{},"length = len(name)",[137,960,961,964],{},[54,962,963],{},"len(name)"," is an expression because it returns a value",[137,966,967,969],{},[54,968,636],{}," is also an expression when Python reads its value",[14,971,972,973,977],{},"If functions still feel unclear, ",[311,974,976],{"href":975},"\u002Flearn\u002Fpython-functions-explained\u002F","Python functions explained"," is a good next step.",[42,979,981],{"id":980},"how-to-identify-each-one-in-code","How to identify each one in code",[14,983,984],{},"When you are not sure, ask these questions.",[212,986,988],{"id":987},"ask-does-this-code-produce-a-value","Ask: does this code produce a value?",[14,990,991],{},"If yes, it is an expression.",[14,993,994],{},"Examples:",[134,996,997,1002,1007,1011,1015,1020],{},[137,998,999],{},[54,1000,1001],{},"10",[137,1003,1004],{},[54,1005,1006],{},"\"cat\"",[137,1008,1009],{},[54,1010,804],{},[137,1012,1013],{},[54,1014,433],{},[137,1016,1017],{},[54,1018,1019],{},"len(text)",[137,1021,1022],{},[54,1023,1024],{},"4 > 2",[212,1026,1028],{"id":1027},"ask-does-this-code-tell-python-to-do-something","Ask: does this code tell Python to do something?",[14,1030,1031],{},"If yes, it is a statement.",[14,1033,994],{},[134,1035,1036,1040,1044,1048,1053,1058],{},[137,1037,1038],{},[54,1039,284],{},[137,1041,1042],{},[54,1043,296],{},[137,1045,1046],{},[54,1047,753],{},[137,1049,1050],{},[54,1051,1052],{},"while count \u003C 3:",[137,1054,1055],{},[54,1056,1057],{},"def greet():",[137,1059,1060],{},[54,1061,290],{},[212,1063,1065],{"id":1064},"look-for-common-statement-patterns","Look for common statement patterns",[14,1067,1068],{},"These often signal statements:",[134,1070,1071,1075,1079,1083,1088,1092],{},[137,1072,1073],{},[54,1074,68],{},[137,1076,1077],{},[54,1078,168],{},[137,1080,1081],{},[54,1082,174],{},[137,1084,1085],{},[54,1086,1087],{},"while",[137,1089,1090],{},[54,1091,186],{},[137,1093,1094],{},[54,1095,180],{},[212,1097,1099],{"id":1098},"look-for-common-expression-patterns","Look for common expression patterns",[14,1101,1102],{},"These often signal expressions:",[134,1104,1105,1108,1111,1114,1117,1120],{},[137,1106,1107],{},"numbers",[137,1109,1110],{},"strings",[137,1112,1113],{},"variable names",[137,1115,1116],{},"calculations",[137,1118,1119],{},"comparisons",[137,1121,1122],{},"function results",[42,1124,1126],{"id":1125},"why-this-matters-for-beginners","Why this matters for beginners",[14,1128,1129],{},"This idea helps more than many beginners expect.",[14,1131,1132],{},"It can help you:",[134,1134,1135,1138,1141,1144,1147],{},[137,1136,1137],{},"read code more clearly",[137,1139,1140],{},"understand what each part of a line is doing",[137,1142,1143],{},"make better sense of error messages",[137,1145,1146],{},"learn variables, conditions, loops, and functions faster",[137,1148,1149],{},"write cleaner Python code",[14,1151,1152],{},"You do not need formal computer science theory here. You just need to recognize:",[134,1154,1155,1158],{},[137,1156,1157],{},"what part gives a value",[137,1159,1160],{},"what part performs an action",[14,1162,1163],{},"That is enough for most beginner Python code.",[42,1165,1167],{"id":1166},"common-mistakes","Common mistakes",[14,1169,1170],{},"Beginners often get confused in these situations.",[212,1172,1174],{"id":1173},"thinking-every-line-of-code-is-only-one-thing","Thinking every line of code is only one thing",[14,1176,1177],{},"Some lines contain both a statement and one or more expressions.",[14,1179,1180],{},"Example:",[47,1182,1184],{"className":49,"code":1183,"language":51,"meta":52,"style":52},"x = 10 + 5\n",[54,1185,1186],{"__ignoreMap":52},[57,1187,1188,1190,1192,1195,1197],{"class":59,"line":60},[57,1189,64],{"class":63},[57,1191,68],{"class":67},[57,1193,1194],{"class":71}," 10",[57,1196,792],{"class":67},[57,1198,515],{"class":71},[134,1200,1201,1204],{},[137,1202,1203],{},"whole line: statement",[137,1205,1206,1209],{},[54,1207,1208],{},"10 + 5",": expression",[212,1211,1213],{"id":1212},"confusing-assignment-with-calculation","Confusing assignment with calculation",[14,1215,1216],{},"In this code:",[47,1218,1220],{"className":49,"code":1219,"language":51,"meta":52,"style":52},"total = price + tax\n",[54,1221,1222],{"__ignoreMap":52},[57,1223,1224,1226,1228,1230,1232],{"class":59,"line":60},[57,1225,520],{"class":63},[57,1227,68],{"class":67},[57,1229,525],{"class":63},[57,1231,89],{"class":67},[57,1233,530],{"class":63},[134,1235,1236,1242],{},[137,1237,1238,1241],{},[54,1239,1240],{},"total = ..."," is the statement",[137,1243,1244,1246],{},[54,1245,560],{}," is the calculation expression",[212,1248,1250,1251,1254],{"id":1249},"assuming-print-is-the-same-as-the-value-it-displays","Assuming ",[54,1252,1253],{},"print()"," is the same as the value it displays",[47,1256,1258],{"className":49,"code":1257,"language":51,"meta":52,"style":52},"x = 7\nprint(x)\n",[54,1259,1260,1269],{"__ignoreMap":52},[57,1261,1262,1264,1266],{"class":59,"line":60},[57,1263,64],{"class":63},[57,1265,68],{"class":67},[57,1267,1268],{"class":71}," 7\n",[57,1270,1271,1273,1275,1277],{"class":59,"line":75},[57,1272,79],{"class":78},[57,1274,83],{"class":82},[57,1276,804],{"class":86},[57,1278,95],{"class":82},[14,1280,1281,1284],{},[54,1282,1283],{},"print(x)"," shows the value on the screen, but it is not the same thing as the value itself.",[134,1286,1287,1291],{},[137,1288,1289,561],{},[54,1290,804],{},[137,1292,1293,1295],{},[54,1294,1283],{}," performs an action",[212,1297,1299],{"id":1298},"not-realizing-conditions-are-expressions","Not realizing conditions are expressions",[47,1301,1303],{"className":49,"code":1302,"language":51,"meta":52,"style":52},"x = 10\nprint(x > 5)\n",[54,1304,1305,1313],{"__ignoreMap":52},[57,1306,1307,1309,1311],{"class":59,"line":60},[57,1308,64],{"class":63},[57,1310,68],{"class":67},[57,1312,72],{"class":71},[57,1314,1315,1317,1319,1321,1323,1325],{"class":59,"line":75},[57,1316,79],{"class":78},[57,1318,83],{"class":82},[57,1320,64],{"class":86},[57,1322,250],{"class":67},[57,1324,92],{"class":71},[57,1326,95],{"class":82},[14,1328,1329,1330,1333,1334,339,1336,128],{},"Here, ",[54,1331,1332],{},"x > 5"," is an expression. It produces ",[54,1335,338],{},[54,1337,342],{},[42,1339,1341],{"id":1340},"try-these-examples-yourself","Try these examples yourself",[14,1343,1344],{},"Run these small examples and notice which parts are statements and which parts are expressions.",[47,1346,1348],{"className":49,"code":1347,"language":51,"meta":52,"style":52},"print(type(5))\nprint(2 + 3)\n\nx = 10\nprint(x)\n\nprint(len(\"hello\"))\nprint(4 > 2)\n",[54,1349,1350,1367,1383,1387,1395,1405,1409,1428],{"__ignoreMap":52},[57,1351,1352,1354,1356,1360,1362,1364],{"class":59,"line":60},[57,1353,79],{"class":78},[57,1355,83],{"class":82},[57,1357,1359],{"class":1358},"sZMiF","type",[57,1361,83],{"class":82},[57,1363,419],{"class":71},[57,1365,1366],{"class":82},"))\n",[57,1368,1369,1371,1373,1376,1378,1381],{"class":59,"line":75},[57,1370,79],{"class":78},[57,1372,83],{"class":82},[57,1374,1375],{"class":71},"2",[57,1377,792],{"class":67},[57,1379,1380],{"class":71}," 3",[57,1382,95],{"class":82},[57,1384,1385],{"class":59,"line":98},[57,1386,102],{"emptyLinePlaceholder":101},[57,1388,1389,1391,1393],{"class":59,"line":105},[57,1390,64],{"class":63},[57,1392,68],{"class":67},[57,1394,72],{"class":71},[57,1396,1397,1399,1401,1403],{"class":59,"line":112},[57,1398,79],{"class":78},[57,1400,83],{"class":82},[57,1402,804],{"class":86},[57,1404,95],{"class":82},[57,1406,1407],{"class":59,"line":118},[57,1408,102],{"emptyLinePlaceholder":101},[57,1410,1412,1414,1416,1418,1420,1422,1424,1426],{"class":59,"line":1411},7,[57,1413,79],{"class":78},[57,1415,83],{"class":82},[57,1417,388],{"class":78},[57,1419,83],{"class":82},[57,1421,266],{"class":265},[57,1423,371],{"class":269},[57,1425,266],{"class":265},[57,1427,1366],{"class":82},[57,1429,1431,1433,1435,1438,1441,1443],{"class":59,"line":1430},8,[57,1432,79],{"class":78},[57,1434,83],{"class":82},[57,1436,1437],{"class":71},"4",[57,1439,1440],{"class":67}," >",[57,1442,789],{"class":71},[57,1444,95],{"class":82},[14,1446,1447],{},"Expected output:",[47,1449,1451],{"className":49,"code":1450,"language":51,"meta":52,"style":52},"\u003Cclass 'int'>\n5\n10\n5\nTrue\n",[54,1452,1453,1474,1478,1483,1487],{"__ignoreMap":52},[57,1454,1455,1458,1462,1465,1468,1471],{"class":59,"line":60},[57,1456,1457],{"class":67},"\u003C",[57,1459,1461],{"class":1460},"sbsja","class",[57,1463,1464],{"class":265}," '",[57,1466,1467],{"class":269},"int",[57,1469,1470],{"class":265},"'",[57,1472,1473],{"class":67},">\n",[57,1475,1476],{"class":59,"line":75},[57,1477,362],{"class":71},[57,1479,1480],{"class":59,"line":98},[57,1481,1482],{"class":71},"10\n",[57,1484,1485],{"class":59,"line":105},[57,1486,362],{"class":71},[57,1488,1489],{"class":59,"line":112},[57,1490,1492],{"class":1491},"s39Yj","True\n",[14,1494,1495],{},"What to notice:",[134,1497,1498,1514,1521],{},[137,1499,1500,1502,1503,1502,1505,1502,1507,1510,1511,1513],{},[54,1501,419],{},", ",[54,1504,818],{},[54,1506,804],{},[54,1508,1509],{},"len(\"hello\")",", and ",[54,1512,1024],{}," are expressions",[137,1515,1516,1517,1520],{},"the ",[54,1518,1519],{},"print(...)"," lines perform actions",[137,1522,1523,1525],{},[54,1524,284],{}," is a statement that sets a variable",[14,1527,1528,1529,128],{},"If you are new to variables, you may also want to read ",[311,1530,1532],{"href":1531},"\u002Fglossary\u002Fwhat-is-a-variable-in-python\u002F","what a variable means in Python",[42,1534,1536],{"id":1535},"faq","FAQ",[212,1538,1540,1541,1543],{"id":1539},"is-print-a-statement-or-an-expression-in-python","Is ",[54,1542,1253],{}," a statement or an expression in Python?",[14,1545,1546,1547,1549,1550,1552],{},"In beginner-focused Python explanations, ",[54,1548,1519],{}," is best treated as a statement because it performs an action. The value inside ",[54,1551,1519],{}," is usually an expression.",[212,1554,1556],{"id":1555},"can-a-statement-contain-an-expression","Can a statement contain an expression?",[14,1558,1559],{},"Yes. This is very common.",[14,1561,1180],{},[47,1563,1565],{"className":49,"code":1564,"language":51,"meta":52,"style":52},"x = 2 + 3\n",[54,1566,1567],{"__ignoreMap":52},[57,1568,1569,1571,1573,1575,1577],{"class":59,"line":60},[57,1570,64],{"class":63},[57,1572,68],{"class":67},[57,1574,789],{"class":71},[57,1576,792],{"class":67},[57,1578,795],{"class":71},[14,1580,1581,1582,128],{},"This is a statement that contains the expression ",[54,1583,818],{},[212,1585,1587],{"id":1586},"is-a-variable-name-an-expression","Is a variable name an expression?",[14,1589,1590,1591,1593],{},"Yes. A variable name like ",[54,1592,804],{}," can be used as an expression because Python evaluates it to its current value.",[212,1595,1597],{"id":1596},"why-do-i-need-to-learn-statements-and-expressions","Why do I need to learn statements and expressions?",[14,1599,1600],{},"It helps you understand how Python code is built. That makes it easier to read examples, write code, and fix mistakes.",[42,1602,1604],{"id":1603},"see-also","See also",[134,1606,1607,1612,1617,1621,1625],{},[137,1608,1609],{},[311,1610,1611],{"href":313},"Python syntax basics explained",[137,1613,1614],{},[311,1615,1616],{"href":465},"Python variables explained for beginners",[137,1618,1619],{},[311,1620,711],{"href":710},[137,1622,1623],{},[311,1624,976],{"href":975},[137,1626,1627],{},[311,1628,1629],{"href":1531},"What is a variable in Python?",[14,1631,1632],{},"Understanding statements and expressions is a strong first step. The next best topics are Python syntax and variables, because these ideas become much clearer when you see them in real beginner code.",[1634,1635,1636],"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 .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}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 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 .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .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 .s2W-s, html code.shiki .s2W-s{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#032F62;--shiki-default-font-style:inherit;--shiki-dark:#9ECBFF;--shiki-dark-font-style:inherit}html pre.shiki code .sithA, html code.shiki .sithA{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#032F62;--shiki-default-font-style:inherit;--shiki-dark:#9ECBFF;--shiki-dark-font-style:inherit}html pre.shiki code .sZMiF, html code.shiki .sZMiF{--shiki-light:#E2931D;--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 .s39Yj, html code.shiki .s39Yj{--shiki-light:#39ADB5;--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":52,"searchDepth":75,"depth":75,"links":1638},[1639,1640,1641,1644,1647,1648,1654,1659,1665,1666,1673,1674,1681],{"id":44,"depth":75,"text":45},{"id":131,"depth":75,"text":132},{"id":151,"depth":75,"text":152,"children":1642},[1643],{"id":214,"depth":98,"text":215},{"id":318,"depth":75,"text":319,"children":1645},[1646],{"id":351,"depth":98,"text":352},{"id":469,"depth":75,"text":470},{"id":578,"depth":75,"text":579,"children":1649},[1650,1651,1652,1653],{"id":585,"depth":98,"text":586},{"id":621,"depth":98,"text":622},{"id":653,"depth":98,"text":654},{"id":714,"depth":98,"text":715},{"id":767,"depth":75,"text":768,"children":1655},[1656,1657,1658],{"id":774,"depth":98,"text":775},{"id":838,"depth":98,"text":839},{"id":906,"depth":98,"text":907},{"id":980,"depth":75,"text":981,"children":1660},[1661,1662,1663,1664],{"id":987,"depth":98,"text":988},{"id":1027,"depth":98,"text":1028},{"id":1064,"depth":98,"text":1065},{"id":1098,"depth":98,"text":1099},{"id":1125,"depth":75,"text":1126},{"id":1166,"depth":75,"text":1167,"children":1667},[1668,1669,1670,1672],{"id":1173,"depth":98,"text":1174},{"id":1212,"depth":98,"text":1213},{"id":1249,"depth":98,"text":1671},"Assuming print() is the same as the value it displays",{"id":1298,"depth":98,"text":1299},{"id":1340,"depth":75,"text":1341},{"id":1535,"depth":75,"text":1536,"children":1675},[1676,1678,1679,1680],{"id":1539,"depth":98,"text":1677},"Is print() a statement or an expression in Python?",{"id":1555,"depth":98,"text":1556},{"id":1586,"depth":98,"text":1587},{"id":1596,"depth":98,"text":1597},{"id":1603,"depth":75,"text":1604},"Master understanding python statements and expressions in our comprehensive Python beginner guide.","md",{},"\u002Flearn\u002Funderstanding-python-statements-and-expressions",{"title":5,"description":1682},"learn\u002Funderstanding-python-statements-and-expressions","8XEMCgq1NOecs-dbGzxPOLHVCvERLF9wzbpQKUvzvQw",1777585506659]