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