[{"data":1,"prerenderedAt":2680},["ShallowReactive",2],{"page-\u002Fpython\u002F03-operators-and-expressions":3},{"id":4,"title":5,"body":6,"description":30,"extension":2674,"meta":2675,"navigation":89,"path":2676,"seo":2677,"stem":2678,"__hash__":2679},"content\u002Fpython\u002F03-operators-and-expressions.md","03 — Operators & Expressions",{"type":7,"value":8,"toc":2652},"minimark",[9,13,183,300,421,583,690,812,977,1072,1175,1279,1398,1595,1793,1909,2012,2161,2307,2432,2530,2648],[10,11,5],"h1",{"id":12},"_03-operators-expressions",[14,15,17,22,76,127],"question-wrapper",{"language":16},"python",[18,19,21],"h3",{"id":20},"q1-what-does-the-following-print","Q1. What does the following print?",[23,24,25],"code-wrapper",{"language":16},[26,27,31],"pre",{"className":28,"code":29,"language":16,"meta":30,"style":30},"language-python shiki shiki-themes github-light github-dark","print(7 \u002F 2)\nprint(7 \u002F\u002F 2)\n","",[32,33,34,60],"code",{"__ignoreMap":30},[35,36,39,43,47,50,54,57],"span",{"class":37,"line":38},"line",1,[35,40,42],{"class":41},"snvgF","print",[35,44,46],{"class":45},"ssxIu","(",[35,48,49],{"class":41},"7",[35,51,53],{"class":52},"svdQ7"," \u002F",[35,55,56],{"class":41}," 2",[35,58,59],{"class":45},")\n",[35,61,63,65,67,69,72,74],{"class":37,"line":62},2,[35,64,42],{"class":41},[35,66,46],{"class":45},[35,68,49],{"class":41},[35,70,71],{"class":52}," \u002F\u002F",[35,73,56],{"class":41},[35,75,59],{"class":45},[77,78,81,99,108,117],"ul",{"className":79},[80],"contains-task-list",[82,83,86,91,92,95,96],"li",{"className":84},[85],"task-list-item",[87,88],"input",{"disabled":89,"type":90},true,"checkbox"," ",[32,93,94],{},"3.5"," then ",[32,97,98],{},"3",[82,100,102,91,104,95,106],{"className":101},[85],[87,103],{"disabled":89,"type":90},[32,105,98],{},[32,107,94],{},[82,109,111,91,113,95,115],{"className":110},[85],[87,112],{"disabled":89,"type":90},[32,114,94],{},[32,116,94],{},[82,118,120,91,122,95,125],{"className":119},[85],[87,121],{"disabled":89,"type":90},[32,123,124],{},"4",[32,126,98],{},[128,129,130,134,146],"details",{},[131,132,133],"summary",{},"Show Answer",[135,136,137,141,142,95,144],"p",{},[138,139,140],"strong",{},"Answer:"," A — ",[32,143,94],{},[32,145,98],{},[135,147,148,91,151,154,155,158,159,162,163,166,167,169,170,172,173,175,176,178,179,182],{},[138,149,150],{},"Explanation:",[32,152,153],{},"\u002F"," is true division and always returns a ",[32,156,157],{},"float"," in Python 3, regardless of operand types. ",[32,160,161],{},"\u002F\u002F"," is floor division; with two ",[32,164,165],{},"int"," operands it returns the floored quotient as an ",[32,168,165],{}," (",[32,171,98],{},", not ",[32,174,94],{},"). B swaps the two operators' behavior. C wrongly assumes ",[32,177,161],{}," also returns a float for int operands. D rounds ",[32,180,181],{},"7 \u002F 2"," incorrectly instead of truncating toward the floor.",[14,184,185,189,230,266],{"language":16},[18,186,188],{"id":187},"q2-what-does-the-following-print","Q2. What does the following print?",[23,190,191],{"language":16},[26,192,194],{"className":28,"code":193,"language":16,"meta":30,"style":30},"x = 5\nprint(1 \u003C x \u003C 10)\n",[32,195,196,207],{"__ignoreMap":30},[35,197,198,201,204],{"class":37,"line":38},[35,199,200],{"class":45},"x ",[35,202,203],{"class":52},"=",[35,205,206],{"class":41}," 5\n",[35,208,209,211,213,216,219,222,225,228],{"class":37,"line":62},[35,210,42],{"class":41},[35,212,46],{"class":45},[35,214,215],{"class":41},"1",[35,217,218],{"class":52}," \u003C",[35,220,221],{"class":45}," x ",[35,223,224],{"class":52},"\u003C",[35,226,227],{"class":41}," 10",[35,229,59],{"class":45},[77,231,233,241,249,258],{"className":232},[80],[82,234,236,91,238],{"className":235},[85],[87,237],{"disabled":89,"type":90},[32,239,240],{},"False",[82,242,244,91,246],{"className":243},[85],[87,245],{"disabled":89,"type":90},[32,247,248],{},"True",[82,250,252,254,255],{"className":251},[85],[87,253],{"disabled":89,"type":90}," Raises ",[32,256,257],{},"SyntaxError",[82,259,261,91,263],{"className":260},[85],[87,262],{"disabled":89,"type":90},[32,264,265],{},"10",[128,267,268,270,277],{},[131,269,133],{},[135,271,272,274,275],{},[138,273,140],{}," B — ",[32,276,248],{},[135,278,279,281,282,285,286,289,290,292,293,295,296,299],{},[138,280,150],{}," Python evaluates the chained comparison ",[32,283,284],{},"1 \u003C x \u003C 10"," as ",[32,287,288],{},"(1 \u003C x) and (x \u003C 10)",". Both sub-comparisons are ",[32,291,248],{}," here, so the result is ",[32,294,248],{},". C is wrong because chained comparisons are ordinary, valid Python syntax. D is wrong because comparison operators always yield a ",[32,297,298],{},"bool",", never one of the compared values.",[14,301,302,306,333,364],{"language":16},[18,303,305],{"id":304},"q3-what-does-the-following-print","Q3. What does the following print?",[23,307,308],{"language":16},[26,309,311],{"className":28,"code":310,"language":16,"meta":30,"style":30},"print(5 \u003C 3 \u003C 10)\n",[32,312,313],{"__ignoreMap":30},[35,314,315,317,319,322,324,327,329,331],{"class":37,"line":38},[35,316,42],{"class":41},[35,318,46],{"class":45},[35,320,321],{"class":41},"5",[35,323,218],{"class":52},[35,325,326],{"class":41}," 3",[35,328,218],{"class":52},[35,330,227],{"class":41},[35,332,59],{"class":45},[77,334,336,343,350,357],{"className":335},[80],[82,337,339,91,341],{"className":338},[85],[87,340],{"disabled":89,"type":90},[32,342,248],{},[82,344,346,254,348],{"className":345},[85],[87,347],{"disabled":89,"type":90},[32,349,257],{},[82,351,353,91,355],{"className":352},[85],[87,354],{"disabled":89,"type":90},[32,356,240],{},[82,358,360,91,362],{"className":359},[85],[87,361],{"disabled":89,"type":90},[32,363,98],{},[128,365,366,368,375],{},[131,367,133],{},[135,369,370,372,373],{},[138,371,140],{}," C — ",[32,374,240],{},[135,376,377,91,379,382,383,386,387,386,390,392,393,396,397,399,400,402,403,406,407,406,410,412,413,417,418,420],{},[138,378,150],{},[32,380,381],{},"5 \u003C 3 \u003C 10"," means ",[32,384,385],{},"(5 \u003C 3) and (3 \u003C 10)"," = ",[32,388,389],{},"False and True",[32,391,240],{},". A programmer used to C-family languages might expect left-to-right evaluation like ",[32,394,395],{},"(5 \u003C 3) \u003C 10",", which — because ",[32,398,298],{}," is a subtype of ",[32,401,165],{}," in Python — would actually compute ",[32,404,405],{},"False \u003C 10"," → ",[32,408,409],{},"0 \u003C 10",[32,411,248],{},". That is genuinely ",[414,415,416],"em",{},"not"," how Python parses a comparison chain, which is why the real answer flips to ",[32,419,240],{},". B is wrong: chaining is valid syntax. D is nonsensical since comparisons never return an operand's value.",[14,422,423,427,493,536],{"language":16},[18,424,426],{"id":425},"q4-what-does-the-following-print","Q4. What does the following print?",[23,428,429],{"language":16},[26,430,432],{"className":28,"code":431,"language":16,"meta":30,"style":30},"def f():\n    print(\"called\")\n    return 5\n\nprint(1 \u003C f() \u003C 10)\n",[32,433,434,446,459,467,473],{"__ignoreMap":30},[35,435,436,439,443],{"class":37,"line":38},[35,437,438],{"class":52},"def",[35,440,442],{"class":441},"sIsaT"," f",[35,444,445],{"class":45},"():\n",[35,447,448,451,453,457],{"class":37,"line":62},[35,449,450],{"class":41},"    print",[35,452,46],{"class":45},[35,454,456],{"class":455},"sJ6F3","\"called\"",[35,458,59],{"class":45},[35,460,462,465],{"class":37,"line":461},3,[35,463,464],{"class":52},"    return",[35,466,206],{"class":41},[35,468,470],{"class":37,"line":469},4,[35,471,472],{"emptyLinePlaceholder":89},"\n",[35,474,476,478,480,482,484,487,489,491],{"class":37,"line":475},5,[35,477,42],{"class":41},[35,479,46],{"class":45},[35,481,215],{"class":41},[35,483,218],{"class":52},[35,485,486],{"class":45}," f() ",[35,488,224],{"class":52},[35,490,227],{"class":41},[35,492,59],{"class":45},[77,494,496,507,516,526],{"className":495},[80],[82,497,499,91,501,504,505],{"className":498},[85],[87,500],{"disabled":89,"type":90},[32,502,503],{},"called"," is printed twice, then ",[32,506,248],{},[82,508,510,91,512,504,514],{"className":509},[85],[87,511],{"disabled":89,"type":90},[32,513,503],{},[32,515,240],{},[82,517,519,91,521,523,524],{"className":518},[85],[87,520],{"disabled":89,"type":90},[32,522,503],{}," is never printed, then ",[32,525,248],{},[82,527,529,91,531,533,534],{"className":528},[85],[87,530],{"disabled":89,"type":90},[32,532,503],{}," is printed once, then ",[32,535,248],{},[128,537,538,540,549],{},[131,539,133],{},[135,541,542,544,545,533,547],{},[138,543,140],{}," D — ",[32,546,503],{},[32,548,248],{},[135,550,551,553,554,557,558,561,562,565,566,568,569,571,572,575,576,579,580,582],{},[138,552,150],{}," In a chained comparison, each middle sub-expression is evaluated only once and its value is reused for both surrounding comparisons. ",[32,555,556],{},"1 \u003C f() \u003C 10"," is not sugar for ",[32,559,560],{},"1 \u003C f() and f() \u003C 10"," (which would call ",[32,563,564],{},"f()"," twice, as A\u002FB assume) — it calls ",[32,567,564],{}," a single time, gets ",[32,570,321],{},", and checks ",[32,573,574],{},"1 \u003C 5"," and ",[32,577,578],{},"5 \u003C 10",", both ",[32,581,248],{},". C is wrong because the middle value must still be computed before any comparison can happen.",[14,584,585,589,628,661],{"language":16},[18,586,588],{"id":587},"q5-what-does-the-following-print","Q5. What does the following print?",[23,590,591],{"language":16},[26,592,594],{"className":28,"code":593,"language":16,"meta":30,"style":30},"a = 100\nb = 100\nprint(a is b)\n",[32,595,596,606,615],{"__ignoreMap":30},[35,597,598,601,603],{"class":37,"line":38},[35,599,600],{"class":45},"a ",[35,602,203],{"class":52},[35,604,605],{"class":41}," 100\n",[35,607,608,611,613],{"class":37,"line":62},[35,609,610],{"class":45},"b ",[35,612,203],{"class":52},[35,614,605],{"class":41},[35,616,617,619,622,625],{"class":37,"line":461},[35,618,42],{"class":41},[35,620,621],{"class":45},"(a ",[35,623,624],{"class":52},"is",[35,626,627],{"class":45}," b)\n",[77,629,631,638,645,653],{"className":630},[80],[82,632,634,91,636],{"className":633},[85],[87,635],{"disabled":89,"type":90},[32,637,248],{},[82,639,641,91,643],{"className":640},[85],[87,642],{"disabled":89,"type":90},[32,644,240],{},[82,646,648,254,650],{"className":647},[85],[87,649],{"disabled":89,"type":90},[32,651,652],{},"NameError",[82,654,656,91,658],{"className":655},[85],[87,657],{"disabled":89,"type":90},[32,659,660],{},"None",[128,662,663,665,671],{},[131,664,133],{},[135,666,667,141,669],{},[138,668,140],{},[32,670,248],{},[135,672,673,675,676,679,680,682,683,686,687,689],{},[138,674,150],{}," CPython pre-allocates and caches small integers from -5 to 256 inclusive as singleton objects. Every reference to the literal ",[32,677,678],{},"100"," resolves to the same cached object, so identity (",[32,681,624],{},") happens to agree with equality (",[32,684,685],{},"==",") here. B is what you'd expect for arbitrary objects in general, but it doesn't hold inside this cached range — which is exactly the trap: it teaches beginners that ",[32,688,624],{}," \"works\" for ints when really it's a caching accident.",[14,691,692,696,730,771],{"language":16},[18,693,695],{"id":694},"q6-what-does-the-following-print","Q6. What does the following print?",[23,697,698],{"language":16},[26,699,701],{"className":28,"code":700,"language":16,"meta":30,"style":30},"a = 1000\nb = 1000\nprint(a is b)\n",[32,702,703,712,720],{"__ignoreMap":30},[35,704,705,707,709],{"class":37,"line":38},[35,706,600],{"class":45},[35,708,203],{"class":52},[35,710,711],{"class":41}," 1000\n",[35,713,714,716,718],{"class":37,"line":62},[35,715,610],{"class":45},[35,717,203],{"class":52},[35,719,711],{"class":41},[35,721,722,724,726,728],{"class":37,"line":461},[35,723,42],{"class":41},[35,725,621],{"class":45},[35,727,624],{"class":52},[35,729,627],{"class":45},[77,731,733,742,754,762],{"className":732},[80],[82,734,736,738,739,741],{"className":735},[85],[87,737],{"disabled":89,"type":90}," Always ",[32,740,240],{},", because 1000 is outside the small-int cache",[82,743,745,747,748,750,751,753],{"className":744},[85],[87,746],{"disabled":89,"type":90}," Unspecified — CPython may print ",[32,749,248],{}," or ",[32,752,240],{}," depending on compile-time constant folding and context, so don't rely on it",[82,755,757,738,759,761],{"className":756},[85],[87,758],{"disabled":89,"type":90},[32,760,248],{},", because Python caches every integer used in a program",[82,763,765,254,767,770],{"className":764},[85],[87,766],{"disabled":89,"type":90},[32,768,769],{},"OverflowError"," since 1000 doesn't fit in a cached slot",[128,772,773,775,784],{},[131,774,133],{},[135,776,777,779,780,750,782,753],{},[138,778,140],{}," B — Unspecified — CPython may print ",[32,781,248],{},[32,783,240],{},[135,785,786,788,789,792,793,795,796,799,800,802,803,805,806,808,809,811],{},[138,787,150],{}," Only integers from -5 to 256 are guaranteed cached singletons. Outside that range, whether ",[32,790,791],{},"a is b"," is ",[32,794,248],{}," depends on implementation details like whether both ",[32,797,798],{},"1000"," literals get folded into the same code object's constant pool (common when both lines are compiled together, e.g. inside one script or function) versus compiled as separate top-level statements at an interactive prompt. This is not part of the language spec and can vary by CPython version or context, so A's \"always ",[32,801,240],{},"\" is too absolute — real CPython often prints ",[32,804,248],{}," in a script. The takeaway either way: never use ",[32,807,624],{}," for integer value comparison, use ",[32,810,685],{},".",[14,813,814,818,883,918],{"language":16},[18,815,817],{"id":816},"q7-what-does-the-following-print","Q7. What does the following print?",[23,819,820],{"language":16},[26,821,823],{"className":28,"code":822,"language":16,"meta":30,"style":30},"a = \"hello\"\nb = \"hello\"\nc = \"\".join([\"he\", \"llo\"])\nprint(a is b, a is c)\n",[32,824,825,834,842,867],{"__ignoreMap":30},[35,826,827,829,831],{"class":37,"line":38},[35,828,600],{"class":45},[35,830,203],{"class":52},[35,832,833],{"class":455}," \"hello\"\n",[35,835,836,838,840],{"class":37,"line":62},[35,837,610],{"class":45},[35,839,203],{"class":52},[35,841,833],{"class":455},[35,843,844,847,849,852,855,858,861,864],{"class":37,"line":461},[35,845,846],{"class":45},"c ",[35,848,203],{"class":52},[35,850,851],{"class":455}," \"\"",[35,853,854],{"class":45},".join([",[35,856,857],{"class":455},"\"he\"",[35,859,860],{"class":45},", ",[35,862,863],{"class":455},"\"llo\"",[35,865,866],{"class":45},"])\n",[35,868,869,871,873,875,878,880],{"class":37,"line":469},[35,870,42],{"class":41},[35,872,621],{"class":45},[35,874,624],{"class":52},[35,876,877],{"class":45}," b, a ",[35,879,624],{"class":52},[35,881,882],{"class":45}," c)\n",[77,884,886,894,902,910],{"className":885},[80],[82,887,889,91,891],{"className":888},[85],[87,890],{"disabled":89,"type":90},[32,892,893],{},"True True",[82,895,897,91,899],{"className":896},[85],[87,898],{"disabled":89,"type":90},[32,900,901],{},"False False",[82,903,905,91,907],{"className":904},[85],[87,906],{"disabled":89,"type":90},[32,908,909],{},"True False",[82,911,913,91,915],{"className":912},[85],[87,914],{"disabled":89,"type":90},[32,916,917],{},"False True",[128,919,920,922,928],{},[131,921,133],{},[135,923,924,372,926],{},[138,925,140],{},[32,927,909],{},[135,929,930,91,932,935,936,575,939,942,943,946,947,91,949,951,952,955,956,959,960,792,963,965,966,792,969,971,972,974,975,811],{},[138,931,150],{},[138,933,934],{},"Idiom"," — ",[32,937,938],{},"a",[32,940,941],{},"b"," are the identical literal ",[32,944,945],{},"\"hello\""," compiled into the same code object, so CPython typically interns\u002Fdedupes it, making ",[32,948,791],{},[32,950,248],{},". ",[32,953,954],{},"c"," is built at runtime via ",[32,957,958],{},"str.join",", producing a fresh string object with equal content but a distinct identity, so ",[32,961,962],{},"a is c",[32,964,240],{}," even though ",[32,967,968],{},"a == c",[32,970,248],{},". String interning is a CPython implementation detail, not a language guarantee — never rely on ",[32,973,624],{}," for string equality, always use ",[32,976,685],{},[14,978,979,983,1007,1041],{"language":16},[18,980,982],{"id":981},"q8-what-does-the-following-print","Q8. What does the following print?",[23,984,985],{"language":16},[26,986,988],{"className":28,"code":987,"language":16,"meta":30,"style":30},"print(-7 \u002F\u002F 2)\n",[32,989,990],{"__ignoreMap":30},[35,991,992,994,996,999,1001,1003,1005],{"class":37,"line":38},[35,993,42],{"class":41},[35,995,46],{"class":45},[35,997,998],{"class":52},"-",[35,1000,49],{"class":41},[35,1002,71],{"class":52},[35,1004,56],{"class":41},[35,1006,59],{"class":45},[77,1008,1010,1018,1025,1033],{"className":1009},[80],[82,1011,1013,91,1015],{"className":1012},[85],[87,1014],{"disabled":89,"type":90},[32,1016,1017],{},"-3",[82,1019,1021,91,1023],{"className":1020},[85],[87,1022],{"disabled":89,"type":90},[32,1024,98],{},[82,1026,1028,91,1030],{"className":1027},[85],[87,1029],{"disabled":89,"type":90},[32,1031,1032],{},"-3.5",[82,1034,1036,91,1038],{"className":1035},[85],[87,1037],{"disabled":89,"type":90},[32,1039,1040],{},"-4",[128,1042,1043,1045,1051],{},[131,1044,133],{},[135,1046,1047,544,1049],{},[138,1048,140],{},[32,1050,1040],{},[135,1052,1053,91,1055,935,1058,1060,1061,1064,1065,1068,1069,1071],{},[138,1054,150],{},[138,1056,1057],{},"Portability",[32,1059,161],{}," floors the true quotient toward negative infinity: ",[32,1062,1063],{},"-7 \u002F 2 = -3.5",", and ",[32,1066,1067],{},"floor(-3.5) = -4",". This differs from C\u002FJava integer division, which truncates toward zero and would give ",[32,1070,1017],{}," (option A) — a common bug when porting numeric code between languages.",[14,1073,1074,1078,1102,1136],{"language":16},[18,1075,1077],{"id":1076},"q9-what-does-the-following-print","Q9. What does the following print?",[23,1079,1080],{"language":16},[26,1081,1083],{"className":28,"code":1082,"language":16,"meta":30,"style":30},"print(-7 % 3)\n",[32,1084,1085],{"__ignoreMap":30},[35,1086,1087,1089,1091,1093,1095,1098,1100],{"class":37,"line":38},[35,1088,42],{"class":41},[35,1090,46],{"class":45},[35,1092,998],{"class":52},[35,1094,49],{"class":41},[35,1096,1097],{"class":52}," %",[35,1099,326],{"class":41},[35,1101,59],{"class":45},[77,1103,1105,1113,1121,1129],{"className":1104},[80],[82,1106,1108,91,1110],{"className":1107},[85],[87,1109],{"disabled":89,"type":90},[32,1111,1112],{},"2",[82,1114,1116,91,1118],{"className":1115},[85],[87,1117],{"disabled":89,"type":90},[32,1119,1120],{},"-1",[82,1122,1124,91,1126],{"className":1123},[85],[87,1125],{"disabled":89,"type":90},[32,1127,1128],{},"-2",[82,1130,1132,91,1134],{"className":1131},[85],[87,1133],{"disabled":89,"type":90},[32,1135,215],{},[128,1137,1138,1140,1146],{},[131,1139,133],{},[135,1141,1142,141,1144],{},[138,1143,140],{},[32,1145,1112],{},[135,1147,1148,91,1150,1152,1153,1156,1157,1160,1161,1164,1165,1168,1169,1171,1172,1174],{},[138,1149,150],{},[138,1151,1057],{}," — Python's ",[32,1154,1155],{},"%"," result always takes the sign of the divisor. ",[32,1158,1159],{},"-7 % 3"," must satisfy ",[32,1162,1163],{},"-7 == 3 * (-7 \u002F\u002F 3) + (-7 % 3)",", i.e. ",[32,1166,1167],{},"-7 == 3 * (-3) + 2",", so the remainder is ",[32,1170,1112],{},". B (",[32,1173,1120],{},") is what a C\u002FJava-style truncating modulo would give, since it takes the sign of the dividend instead.",[14,1176,1177,1181,1210,1245],{"language":16},[18,1178,1180],{"id":1179},"q10-what-does-the-following-print","Q10. What does the following print?",[23,1182,1183],{"language":16},[26,1184,1186],{"className":28,"code":1185,"language":16,"meta":30,"style":30},"print(divmod(-7, 3))\n",[32,1187,1188],{"__ignoreMap":30},[35,1189,1190,1192,1194,1197,1199,1201,1203,1205,1207],{"class":37,"line":38},[35,1191,42],{"class":41},[35,1193,46],{"class":45},[35,1195,1196],{"class":41},"divmod",[35,1198,46],{"class":45},[35,1200,998],{"class":52},[35,1202,49],{"class":41},[35,1204,860],{"class":45},[35,1206,98],{"class":41},[35,1208,1209],{"class":45},"))\n",[77,1211,1213,1221,1229,1237],{"className":1212},[80],[82,1214,1216,91,1218],{"className":1215},[85],[87,1217],{"disabled":89,"type":90},[32,1219,1220],{},"(-2, -1)",[82,1222,1224,91,1226],{"className":1223},[85],[87,1225],{"disabled":89,"type":90},[32,1227,1228],{},"(-3, 2)",[82,1230,1232,91,1234],{"className":1231},[85],[87,1233],{"disabled":89,"type":90},[32,1235,1236],{},"(-3, -1)",[82,1238,1240,91,1242],{"className":1239},[85],[87,1241],{"disabled":89,"type":90},[32,1243,1244],{},"(-2, 2)",[128,1246,1247,1249,1255],{},[131,1248,133],{},[135,1250,1251,274,1253],{},[138,1252,140],{},[32,1254,1228],{},[135,1256,1257,91,1259,1262,1263,1266,1267,1270,1271,1274,1275,1278],{},[138,1258,150],{},[32,1260,1261],{},"divmod(a, b)"," returns the pair ",[32,1264,1265],{},"(a \u002F\u002F b, a % b)",". Here ",[32,1268,1269],{},"-7 \u002F\u002F 3 = -3"," (floors toward negative infinity) and ",[32,1272,1273],{},"-7 % 3 = 2"," (sign of the divisor), so ",[32,1276,1277],{},"divmod(-7, 3)"," bundles both results from the same floor-division\u002Fmodulo rules seen in Q8\u002FQ9 into one tuple.",[14,1280,1281,1285,1311,1346],{"language":16},[18,1282,1284],{"id":1283},"q11-what-does-the-following-print","Q11. What does the following print?",[23,1286,1287],{"language":16},[26,1288,1290],{"className":28,"code":1289,"language":16,"meta":30,"style":30},"print(2 ** 3 ** 2)\n",[32,1291,1292],{"__ignoreMap":30},[35,1293,1294,1296,1298,1300,1303,1305,1307,1309],{"class":37,"line":38},[35,1295,42],{"class":41},[35,1297,46],{"class":45},[35,1299,1112],{"class":41},[35,1301,1302],{"class":52}," **",[35,1304,326],{"class":41},[35,1306,1302],{"class":52},[35,1308,56],{"class":41},[35,1310,59],{"class":45},[77,1312,1314,1322,1330,1338],{"className":1313},[80],[82,1315,1317,91,1319],{"className":1316},[85],[87,1318],{"disabled":89,"type":90},[32,1320,1321],{},"64",[82,1323,1325,91,1327],{"className":1324},[85],[87,1326],{"disabled":89,"type":90},[32,1328,1329],{},"1024",[82,1331,1333,91,1335],{"className":1332},[85],[87,1334],{"disabled":89,"type":90},[32,1336,1337],{},"512",[82,1339,1341,91,1343],{"className":1340},[85],[87,1342],{"disabled":89,"type":90},[32,1344,1345],{},"216",[128,1347,1348,1350,1356],{},[131,1349,133],{},[135,1351,1352,372,1354],{},[138,1353,140],{},[32,1355,1337],{},[135,1357,1358,1360,1361,1364,1365,386,1368,386,1371,1373,1374,386,1377,386,1380,1382,1383,1385,1386,860,1389,860,1391,1394,1395,1397],{},[138,1359,150],{}," Unlike almost every other binary operator in Python, ",[32,1362,1363],{},"**"," is right-associative, so this is ",[32,1366,1367],{},"2 ** (3 ** 2)",[32,1369,1370],{},"2 ** 9",[32,1372,1337],{},". Left-associative evaluation, ",[32,1375,1376],{},"(2 ** 3) ** 2",[32,1378,1379],{},"8 ** 2",[32,1381,1321],{}," (option A), is what you'd get if ",[32,1384,1363],{}," behaved like ",[32,1387,1388],{},"+",[32,1390,998],{},[32,1392,1393],{},"*",", or ",[32,1396,153],{}," — it's the one operator where associativity genuinely trips people up.",[14,1399,1400,1404,1512,1545],{"language":16},[18,1401,1403],{"id":1402},"q12-what-does-the-following-print","Q12. What does the following print?",[23,1405,1406],{"language":16},[26,1407,1409],{"className":28,"code":1408,"language":16,"meta":30,"style":30},"class Money:\n    def __init__(self, amount):\n        self.amount = amount\n\n    def __radd__(self, other):\n        return Money(self.amount + other)\n\nresult = 5 + Money(10)\nprint(result.amount)\n",[32,1410,1411,1422,1433,1446,1450,1460,1479,1484,1504],{"__ignoreMap":30},[35,1412,1413,1416,1419],{"class":37,"line":38},[35,1414,1415],{"class":52},"class",[35,1417,1418],{"class":441}," Money",[35,1420,1421],{"class":45},":\n",[35,1423,1424,1427,1430],{"class":37,"line":62},[35,1425,1426],{"class":52},"    def",[35,1428,1429],{"class":41}," __init__",[35,1431,1432],{"class":45},"(self, amount):\n",[35,1434,1435,1438,1441,1443],{"class":37,"line":461},[35,1436,1437],{"class":41},"        self",[35,1439,1440],{"class":45},".amount ",[35,1442,203],{"class":52},[35,1444,1445],{"class":45}," amount\n",[35,1447,1448],{"class":37,"line":469},[35,1449,472],{"emptyLinePlaceholder":89},[35,1451,1452,1454,1457],{"class":37,"line":475},[35,1453,1426],{"class":52},[35,1455,1456],{"class":41}," __radd__",[35,1458,1459],{"class":45},"(self, other):\n",[35,1461,1463,1466,1469,1472,1474,1476],{"class":37,"line":1462},6,[35,1464,1465],{"class":52},"        return",[35,1467,1468],{"class":45}," Money(",[35,1470,1471],{"class":41},"self",[35,1473,1440],{"class":45},[35,1475,1388],{"class":52},[35,1477,1478],{"class":45}," other)\n",[35,1480,1482],{"class":37,"line":1481},7,[35,1483,472],{"emptyLinePlaceholder":89},[35,1485,1487,1490,1492,1495,1498,1500,1502],{"class":37,"line":1486},8,[35,1488,1489],{"class":45},"result ",[35,1491,203],{"class":52},[35,1493,1494],{"class":41}," 5",[35,1496,1497],{"class":52}," +",[35,1499,1468],{"class":45},[35,1501,265],{"class":41},[35,1503,59],{"class":45},[35,1505,1507,1509],{"class":37,"line":1506},9,[35,1508,42],{"class":41},[35,1510,1511],{"class":45},"(result.amount)\n",[77,1513,1515,1523,1530,1537],{"className":1514},[80],[82,1516,1518,254,1520],{"className":1517},[85],[87,1519],{"disabled":89,"type":90},[32,1521,1522],{},"TypeError",[82,1524,1526,91,1528],{"className":1525},[85],[87,1527],{"disabled":89,"type":90},[32,1529,321],{},[82,1531,1533,91,1535],{"className":1532},[85],[87,1534],{"disabled":89,"type":90},[32,1536,660],{},[82,1538,1540,91,1542],{"className":1539},[85],[87,1541],{"disabled":89,"type":90},[32,1543,1544],{},"15",[128,1546,1547,1549,1555],{},[131,1548,133],{},[135,1550,1551,544,1553],{},[138,1552,140],{},[32,1554,1544],{},[135,1556,1557,1559,1560,1563,1564,951,1567,1569,1570,1573,1574,1577,1578,1581,1582,1585,1586,1588,1589,1592,1593,811],{},[138,1558,150],{}," Python evaluates ",[32,1561,1562],{},"5 + Money(10)"," by first trying ",[32,1565,1566],{},"int.__add__(5, Money(10))",[32,1568,165],{}," has no idea how to add a ",[32,1571,1572],{},"Money",", so that returns ",[32,1575,1576],{},"NotImplemented",". Python then falls back to the reflected method on the right operand, ",[32,1579,1580],{},"Money(10).__radd__(5)",", which returns ",[32,1583,1584],{},"Money(15)",". A would only be correct if ",[32,1587,1572],{}," defined no ",[32,1590,1591],{},"__radd__"," at all — then both dunder attempts fail and Python genuinely raises ",[32,1594,1522],{},[14,1596,1597,1601,1691,1726],{"language":16},[18,1598,1600],{"id":1599},"q13-what-does-the-following-print","Q13. What does the following print?",[23,1602,1603],{"language":16},[26,1604,1606],{"className":28,"code":1605,"language":16,"meta":30,"style":30},"a = [1, 2]\nb = a\na += [3]\n\nx = 10\ny = x\nx += 1\n\nprint(b, y)\n",[32,1607,1608,1626,1635,1648,1652,1661,1671,1680,1684],{"__ignoreMap":30},[35,1609,1610,1612,1614,1617,1619,1621,1623],{"class":37,"line":38},[35,1611,600],{"class":45},[35,1613,203],{"class":52},[35,1615,1616],{"class":45}," [",[35,1618,215],{"class":41},[35,1620,860],{"class":45},[35,1622,1112],{"class":41},[35,1624,1625],{"class":45},"]\n",[35,1627,1628,1630,1632],{"class":37,"line":62},[35,1629,610],{"class":45},[35,1631,203],{"class":52},[35,1633,1634],{"class":45}," a\n",[35,1636,1637,1639,1642,1644,1646],{"class":37,"line":461},[35,1638,600],{"class":45},[35,1640,1641],{"class":52},"+=",[35,1643,1616],{"class":45},[35,1645,98],{"class":41},[35,1647,1625],{"class":45},[35,1649,1650],{"class":37,"line":469},[35,1651,472],{"emptyLinePlaceholder":89},[35,1653,1654,1656,1658],{"class":37,"line":475},[35,1655,200],{"class":45},[35,1657,203],{"class":52},[35,1659,1660],{"class":41}," 10\n",[35,1662,1663,1666,1668],{"class":37,"line":1462},[35,1664,1665],{"class":45},"y ",[35,1667,203],{"class":52},[35,1669,1670],{"class":45}," x\n",[35,1672,1673,1675,1677],{"class":37,"line":1481},[35,1674,200],{"class":45},[35,1676,1641],{"class":52},[35,1678,1679],{"class":41}," 1\n",[35,1681,1682],{"class":37,"line":1486},[35,1683,472],{"emptyLinePlaceholder":89},[35,1685,1686,1688],{"class":37,"line":1506},[35,1687,42],{"class":41},[35,1689,1690],{"class":45},"(b, y)\n",[77,1692,1694,1702,1710,1718],{"className":1693},[80],[82,1695,1697,91,1699],{"className":1696},[85],[87,1698],{"disabled":89,"type":90},[32,1700,1701],{},"[1, 2, 3] 10",[82,1703,1705,91,1707],{"className":1704},[85],[87,1706],{"disabled":89,"type":90},[32,1708,1709],{},"[1, 2] 10",[82,1711,1713,91,1715],{"className":1712},[85],[87,1714],{"disabled":89,"type":90},[32,1716,1717],{},"[1, 2, 3] 11",[82,1719,1721,91,1723],{"className":1720},[85],[87,1722],{"disabled":89,"type":90},[32,1724,1725],{},"[1, 2] 11",[128,1727,1728,1730,1736],{},[131,1729,133],{},[135,1731,1732,141,1734],{},[138,1733,140],{},[32,1735,1701],{},[135,1737,1738,1740,1741,1744,1745,1748,1749,1751,1752,1754,1755,1757,1758,1761,1762,1765,1766,1768,1769,1772,1773,1776,1777,1780,1781,1783,1784,1786,1787,1789,1790,1792],{},[138,1739,150],{}," Lists are mutable, so ",[32,1742,1743],{},"a += [3]"," invokes ",[32,1746,1747],{},"list.__iadd__",", which mutates the list in place and keeps ",[32,1750,938],{},"'s identity unchanged — since ",[32,1753,941],{}," is an alias to that same object, ",[32,1756,941],{}," also shows ",[32,1759,1760],{},"[1, 2, 3]",". Ints are immutable, so ",[32,1763,1764],{},"x += 1"," can't mutate ",[32,1767,265],{}," in place; it rebinds ",[32,1770,1771],{},"x"," to a brand-new object ",[32,1774,1775],{},"11",", leaving ",[32,1778,1779],{},"y"," still pointing at the original ",[32,1782,265],{},". Option C's ",[32,1785,1775],{}," for ",[32,1788,1779],{}," is the mistake of assuming ",[32,1791,1641],{}," always ripples to every alias the way it does for lists.",[14,1794,1795,1799,1828,1860],{"language":16},[18,1796,1798],{"id":1797},"q14-what-does-the-following-print","Q14. What does the following print?",[23,1800,1801],{"language":16},[26,1802,1804],{"className":28,"code":1803,"language":16,"meta":30,"style":30},"print(0.1 + 0.2 == 0.3)\n",[32,1805,1806],{"__ignoreMap":30},[35,1807,1808,1810,1812,1815,1817,1820,1823,1826],{"class":37,"line":38},[35,1809,42],{"class":41},[35,1811,46],{"class":45},[35,1813,1814],{"class":41},"0.1",[35,1816,1497],{"class":52},[35,1818,1819],{"class":41}," 0.2",[35,1821,1822],{"class":52}," ==",[35,1824,1825],{"class":41}," 0.3",[35,1827,59],{"class":45},[77,1829,1831,1838,1845,1852],{"className":1830},[80],[82,1832,1834,91,1836],{"className":1833},[85],[87,1835],{"disabled":89,"type":90},[32,1837,248],{},[82,1839,1841,91,1843],{"className":1840},[85],[87,1842],{"disabled":89,"type":90},[32,1844,240],{},[82,1846,1848,254,1850],{"className":1847},[85],[87,1849],{"disabled":89,"type":90},[32,1851,1522],{},[82,1853,1855,91,1857],{"className":1854},[85],[87,1856],{"disabled":89,"type":90},[32,1858,1859],{},"0.3",[128,1861,1862,1864,1870],{},[131,1863,133],{},[135,1865,1866,274,1868],{},[138,1867,140],{},[32,1869,240],{},[135,1871,1872,91,1874,935,1877,860,1879,1064,1882,1884,1885,1888,1889,1892,1893,1895,1896,1899,1900,1902,1903,1906,1907,811],{},[138,1873,150],{},[138,1875,1876],{},"Debug",[32,1878,1814],{},[32,1880,1881],{},"0.2",[32,1883,1859],{}," have no exact representation in IEEE-754 binary floating point. ",[32,1886,1887],{},"0.1 + 0.2"," actually evaluates to ",[32,1890,1891],{},"0.30000000000000004",", which is not bit-for-bit equal to the literal ",[32,1894,1859],{},". This is a floating-point representation issue, not a Python-specific bug, and it also underlies mixed-type arithmetic promotion (",[32,1897,1898],{},"int + float"," always promotes to ",[32,1901,157],{},", inheriting these same representation limits). The fix is comparing with a tolerance, e.g. ",[32,1904,1905],{},"math.isclose(0.1 + 0.2, 0.3)",", instead of ",[32,1908,685],{},[14,1910,1911,1915,1939,1971],{"language":16},[18,1912,1914],{"id":1913},"q15-what-does-the-following-print","Q15. What does the following print?",[23,1916,1917],{"language":16},[26,1918,1920],{"className":28,"code":1919,"language":16,"meta":30,"style":30},"print(0 or \"default\")\n",[32,1921,1922],{"__ignoreMap":30},[35,1923,1924,1926,1928,1931,1934,1937],{"class":37,"line":38},[35,1925,42],{"class":41},[35,1927,46],{"class":45},[35,1929,1930],{"class":41},"0",[35,1932,1933],{"class":52}," or",[35,1935,1936],{"class":455}," \"default\"",[35,1938,59],{"class":45},[77,1940,1942,1949,1956,1964],{"className":1941},[80],[82,1943,1945,91,1947],{"className":1944},[85],[87,1946],{"disabled":89,"type":90},[32,1948,248],{},[82,1950,1952,91,1954],{"className":1951},[85],[87,1953],{"disabled":89,"type":90},[32,1955,1930],{},[82,1957,1959,91,1961],{"className":1958},[85],[87,1960],{"disabled":89,"type":90},[32,1962,1963],{},"default",[82,1965,1967,91,1969],{"className":1966},[85],[87,1968],{"disabled":89,"type":90},[32,1970,240],{},[128,1972,1973,1975,1981],{},[131,1974,133],{},[135,1976,1977,372,1979],{},[138,1978,140],{},[32,1980,1963],{},[135,1982,1983,91,1985,935,1987,153,1990,1993,1994,1996,1997,1999,2000,2002,2003,2006,2007,2009,2010,811],{},[138,1984,150],{},[138,1986,934],{},[32,1988,1989],{},"and",[32,1991,1992],{},"or"," don't coerce their result to ",[32,1995,298],{},"; they evaluate operands left to right and return the first operand that decides the outcome, as-is. ",[32,1998,1930],{}," is falsy, so ",[32,2001,1992],{}," moves on and returns the actual value ",[32,2004,2005],{},"\"default\"",". B is what a strict boolean-",[32,2008,1992],{}," language would give; A\u002FD wrongly assume Python's logical operators always return ",[32,2011,298],{},[14,2013,2014,2018,2066,2097],{"language":16},[18,2015,2017],{"id":2016},"q16-what-does-the-following-print","Q16. What does the following print?",[23,2019,2020],{"language":16},[26,2021,2023],{"className":28,"code":2022,"language":16,"meta":30,"style":30},"def choose(flag):\n    return flag and 0 or 5\n\nprint(choose(3))\n",[32,2024,2025,2035,2051,2055],{"__ignoreMap":30},[35,2026,2027,2029,2032],{"class":37,"line":38},[35,2028,438],{"class":52},[35,2030,2031],{"class":441}," choose",[35,2033,2034],{"class":45},"(flag):\n",[35,2036,2037,2039,2042,2044,2047,2049],{"class":37,"line":62},[35,2038,464],{"class":52},[35,2040,2041],{"class":45}," flag ",[35,2043,1989],{"class":52},[35,2045,2046],{"class":41}," 0",[35,2048,1933],{"class":52},[35,2050,206],{"class":41},[35,2052,2053],{"class":37,"line":461},[35,2054,472],{"emptyLinePlaceholder":89},[35,2056,2057,2059,2062,2064],{"class":37,"line":469},[35,2058,42],{"class":41},[35,2060,2061],{"class":45},"(choose(",[35,2063,98],{"class":41},[35,2065,1209],{"class":45},[77,2067,2069,2076,2083,2090],{"className":2068},[80],[82,2070,2072,91,2074],{"className":2071},[85],[87,2073],{"disabled":89,"type":90},[32,2075,1930],{},[82,2077,2079,91,2081],{"className":2078},[85],[87,2080],{"disabled":89,"type":90},[32,2082,98],{},[82,2084,2086,91,2088],{"className":2085},[85],[87,2087],{"disabled":89,"type":90},[32,2089,660],{},[82,2091,2093,91,2095],{"className":2092},[85],[87,2094],{"disabled":89,"type":90},[32,2096,321],{},[128,2098,2099,2101,2107],{},[131,2100,133],{},[135,2102,2103,544,2105],{},[138,2104,140],{},[32,2106,321],{},[135,2108,2109,91,2111,935,2113,2116,2117,2119,2120,2122,2123,2125,2126,2116,2129,2131,2132,2134,2135,2137,2138,2141,2142,2144,2145,2148,2149,2152,2153,2156,2157,2160],{},[138,2110,150],{},[138,2112,934],{},[32,2114,2115],{},"3 and 0"," evaluates to ",[32,2118,1930],{},", because the left operand ",[32,2121,98],{}," is truthy so ",[32,2124,1989],{}," evaluates and returns the right operand. Then ",[32,2127,2128],{},"0 or 5",[32,2130,321],{},", because ",[32,2133,1930],{}," is falsy so ",[32,2136,1992],{}," moves on to its right operand. ",[32,2139,2140],{},"choose"," was clearly meant to return ",[32,2143,1930],{}," when ",[32,2146,2147],{},"flag"," is truthy, but the classic ",[32,2150,2151],{},"flag and X or Y"," idiom silently breaks whenever ",[32,2154,2155],{},"X"," itself is falsy — which is exactly why Python's conditional expression ",[32,2158,2159],{},"0 if flag else 5"," should be preferred over this pattern. A is the \"intended\" answer a reader would wrongly expect.",[14,2162,2163,2167,2206,2241],{"language":16},[18,2164,2166],{"id":2165},"q17-what-does-the-following-print","Q17. What does the following print?",[23,2168,2169],{"language":16},[26,2170,2172],{"className":28,"code":2171,"language":16,"meta":30,"style":30},"a = 5\nb = 3\nprint(a & b, a and b)\n",[32,2173,2174,2182,2191],{"__ignoreMap":30},[35,2175,2176,2178,2180],{"class":37,"line":38},[35,2177,600],{"class":45},[35,2179,203],{"class":52},[35,2181,206],{"class":41},[35,2183,2184,2186,2188],{"class":37,"line":62},[35,2185,610],{"class":45},[35,2187,203],{"class":52},[35,2189,2190],{"class":41}," 3\n",[35,2192,2193,2195,2197,2200,2202,2204],{"class":37,"line":461},[35,2194,42],{"class":41},[35,2196,621],{"class":45},[35,2198,2199],{"class":52},"&",[35,2201,877],{"class":45},[35,2203,1989],{"class":52},[35,2205,627],{"class":45},[77,2207,2209,2217,2225,2233],{"className":2208},[80],[82,2210,2212,91,2214],{"className":2211},[85],[87,2213],{"disabled":89,"type":90},[32,2215,2216],{},"1 3",[82,2218,2220,91,2222],{"className":2219},[85],[87,2221],{"disabled":89,"type":90},[32,2223,2224],{},"1 1",[82,2226,2228,91,2230],{"className":2227},[85],[87,2229],{"disabled":89,"type":90},[32,2231,2232],{},"7 3",[82,2234,2236,91,2238],{"className":2235},[85],[87,2237],{"disabled":89,"type":90},[32,2239,2240],{},"7 5",[128,2242,2243,2245,2251],{},[131,2244,133],{},[135,2246,2247,141,2249],{},[138,2248,140],{},[32,2250,2216],{},[135,2252,2253,91,2255,2257,2258,169,2260,2263,2264,91,2266,169,2268,2271,2272,386,2275,951,2277,2279,2280,169,2282,2284,2285,2287,2288,169,2290,2292,2293,153,2295,2298,2299,153,2301,2303,2304,2306],{},[138,2254,150],{},[32,2256,2199],{}," is the bitwise AND operator: ",[32,2259,321],{},[32,2261,2262],{},"101",") ",[32,2265,2199],{},[32,2267,98],{},[32,2269,2270],{},"011",") = ",[32,2273,2274],{},"001",[32,2276,215],{},[32,2278,1989],{}," is the logical operator and, as in Q15, returns an actual operand rather than a recombined value: since ",[32,2281,938],{},[32,2283,321],{},") is truthy, ",[32,2286,1989],{}," evaluates and returns ",[32,2289,941],{},[32,2291,98],{},"). This distinction matters a lot with array-like objects (e.g. NumPy arrays or pandas Series), where ",[32,2294,2199],{},[32,2296,2297],{},"|"," are required for element-wise boolean logic because ",[32,2300,1989],{},[32,2302,1992],{}," can't be overloaded to short-circuit per-element and instead try to coerce the whole array to a single ",[32,2305,298],{},", raising an error.",[14,2308,2309,2313,2352,2383],{"language":16},[18,2310,2312],{"id":2311},"q18-what-does-the-following-print","Q18. What does the following print?",[23,2314,2315],{"language":16},[26,2316,2318],{"className":28,"code":2317,"language":16,"meta":30,"style":30},"a = 1\nb = 2\nprint(not a == b)\n",[32,2319,2320,2328,2337],{"__ignoreMap":30},[35,2321,2322,2324,2326],{"class":37,"line":38},[35,2323,600],{"class":45},[35,2325,203],{"class":52},[35,2327,1679],{"class":41},[35,2329,2330,2332,2334],{"class":37,"line":62},[35,2331,610],{"class":45},[35,2333,203],{"class":52},[35,2335,2336],{"class":41}," 2\n",[35,2338,2339,2341,2343,2345,2348,2350],{"class":37,"line":461},[35,2340,42],{"class":41},[35,2342,46],{"class":45},[35,2344,416],{"class":52},[35,2346,2347],{"class":45}," a ",[35,2349,685],{"class":52},[35,2351,627],{"class":45},[77,2353,2355,2362,2369,2376],{"className":2354},[80],[82,2356,2358,91,2360],{"className":2357},[85],[87,2359],{"disabled":89,"type":90},[32,2361,240],{},[82,2363,2365,91,2367],{"className":2364},[85],[87,2366],{"disabled":89,"type":90},[32,2368,248],{},[82,2370,2372,254,2374],{"className":2371},[85],[87,2373],{"disabled":89,"type":90},[32,2375,257],{},[82,2377,2379,91,2381],{"className":2378},[85],[87,2380],{"disabled":89,"type":90},[32,2382,215],{},[128,2384,2385,2387,2393],{},[131,2386,133],{},[135,2388,2389,274,2391],{},[138,2390,140],{},[32,2392,248],{},[135,2394,2395,91,2397,2399,2400,386,2403,386,2406,2408,2409,1164,2412,406,2415,2417,2418,575,2421,2424,2425,2428,2429,811],{},[138,2396,150],{},[32,2398,416],{}," binds more loosely than comparison operators, so this parses as ",[32,2401,2402],{},"not (a == b)",[32,2404,2405],{},"not False",[32,2407,248],{},". A is the trap answer from misreading it as ",[32,2410,2411],{},"(not a) == b",[32,2413,2414],{},"False == 2",[32,2416,240],{}," — but that grouping is not how Python's operator precedence actually works. This same looser-than-comparison binding is why ",[32,2419,2420],{},"is not",[32,2422,2423],{},"not in"," exist as their own compound operators rather than requiring ",[32,2426,2427],{},"not (x is y)"," \u002F ",[32,2430,2431],{},"not (x in y)",[14,2433,2434,2438,2460,2491],{"language":16},[18,2435,2437],{"id":2436},"q19-what-does-the-following-print","Q19. What does the following print?",[23,2439,2440],{"language":16},[26,2441,2443],{"className":28,"code":2442,"language":16,"meta":30,"style":30},"print(1 \u003C \"a\")\n",[32,2444,2445],{"__ignoreMap":30},[35,2446,2447,2449,2451,2453,2455,2458],{"class":37,"line":38},[35,2448,42],{"class":41},[35,2450,46],{"class":45},[35,2452,215],{"class":41},[35,2454,218],{"class":52},[35,2456,2457],{"class":455}," \"a\"",[35,2459,59],{"class":45},[77,2461,2463,2470,2477,2484],{"className":2462},[80],[82,2464,2466,91,2468],{"className":2465},[85],[87,2467],{"disabled":89,"type":90},[32,2469,248],{},[82,2471,2473,91,2475],{"className":2472},[85],[87,2474],{"disabled":89,"type":90},[32,2476,240],{},[82,2478,2480,254,2482],{"className":2479},[85],[87,2481],{"disabled":89,"type":90},[32,2483,1522],{},[82,2485,2487,91,2489],{"className":2486},[85],[87,2488],{"disabled":89,"type":90},[32,2490,215],{},[128,2492,2493,2495,2502],{},[131,2494,133],{},[135,2496,2497,2499,2500],{},[138,2498,140],{}," C — Raises ",[32,2501,1522],{},[135,2503,2504,91,2506,2508,2509,2511,2512,2515,2516,153,2519,2522,2523,2525,2526,2529],{},[138,2505,150],{},[138,2507,1057],{}," — Python 3 refuses to order-compare incompatible types: ",[32,2510,165],{}," has no defined ordering against ",[32,2513,2514],{},"str",", both types' ",[32,2517,2518],{},"__lt__",[32,2520,2521],{},"__gt__"," return ",[32,2524,1576],{}," for each other, so Python raises ",[32,2527,2528],{},"TypeError: '\u003C' not supported between instances of 'int' and 'str'",". This is a deliberate break from Python 2, which allowed cross-type comparisons using an arbitrary-but-consistent rule — code ported from Python 2 that relied on sorting mixed-type lists can crash outright in Python 3.",[14,2531,2532,2536,2577,2608],{"language":16},[18,2533,2535],{"id":2534},"q20-what-does-the-following-print","Q20. What does the following print?",[23,2537,2538],{"language":16},[26,2539,2541],{"className":28,"code":2540,"language":16,"meta":30,"style":30},"nan = float('nan')\nprint(nan == nan, nan is nan)\n",[32,2542,2543,2560],{"__ignoreMap":30},[35,2544,2545,2548,2550,2553,2555,2558],{"class":37,"line":38},[35,2546,2547],{"class":45},"nan ",[35,2549,203],{"class":52},[35,2551,2552],{"class":41}," float",[35,2554,46],{"class":45},[35,2556,2557],{"class":455},"'nan'",[35,2559,59],{"class":45},[35,2561,2562,2564,2567,2569,2572,2574],{"class":37,"line":62},[35,2563,42],{"class":41},[35,2565,2566],{"class":45},"(nan ",[35,2568,685],{"class":52},[35,2570,2571],{"class":45}," nan, nan ",[35,2573,624],{"class":52},[35,2575,2576],{"class":45}," nan)\n",[77,2578,2580,2587,2594,2601],{"className":2579},[80],[82,2581,2583,91,2585],{"className":2582},[85],[87,2584],{"disabled":89,"type":90},[32,2586,893],{},[82,2588,2590,91,2592],{"className":2589},[85],[87,2591],{"disabled":89,"type":90},[32,2593,909],{},[82,2595,2597,91,2599],{"className":2596},[85],[87,2598],{"disabled":89,"type":90},[32,2600,901],{},[82,2602,2604,91,2606],{"className":2603},[85],[87,2605],{"disabled":89,"type":90},[32,2607,917],{},[128,2609,2610,2612,2618],{},[131,2611,133],{},[135,2613,2614,544,2616],{},[138,2615,140],{},[32,2617,917],{},[135,2619,2620,91,2622,2624,2625,792,2628,2630,2631,2634,2635,792,2638,2640,2641,2643,2644,2647],{},[138,2621,150],{},[138,2623,1876],{}," — IEEE-754 defines NaN as unordered and unequal to everything, including itself, so ",[32,2626,2627],{},"nan == nan",[32,2629,240],{}," even though both sides are literally the same object — ",[32,2632,2633],{},"float.__eq__"," follows the IEEE rule rather than special-casing identical operands. ",[32,2636,2637],{},"nan is nan",[32,2639,248],{}," simply because both names refer to the exact same object; identity is trivially reflexive and unaffected by IEEE semantics. Practical implication: a NaN value can silently fail ",[32,2642,685],{},"-based lookups or filters, but CPython's dict\u002Fset implementation checks identity before falling back to equality, so the ",[414,2645,2646],{},"same"," NaN object can still be found again as a dict key — a different, merely equal-valued NaN object cannot.",[2649,2650,2651],"style",{},"html pre.shiki code .snvgF, html code.shiki .snvgF{--shiki-default:#005CC5;--shiki-github-dark:#79B8FF}html pre.shiki code .ssxIu, html code.shiki .ssxIu{--shiki-default:#24292E;--shiki-github-dark:#E1E4E8}html pre.shiki code .svdQ7, html code.shiki .svdQ7{--shiki-default:#D73A49;--shiki-github-dark:#F97583}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 .github-dark .shiki span {color: var(--shiki-github-dark);background: var(--shiki-github-dark-bg);font-style: var(--shiki-github-dark-font-style);font-weight: var(--shiki-github-dark-font-weight);text-decoration: var(--shiki-github-dark-text-decoration);}html.github-dark .shiki span {color: var(--shiki-github-dark);background: var(--shiki-github-dark-bg);font-style: var(--shiki-github-dark-font-style);font-weight: var(--shiki-github-dark-font-weight);text-decoration: var(--shiki-github-dark-text-decoration);}html pre.shiki code .sIsaT, html code.shiki .sIsaT{--shiki-default:#6F42C1;--shiki-github-dark:#B392F0}html pre.shiki code .sJ6F3, html code.shiki .sJ6F3{--shiki-default:#032F62;--shiki-github-dark:#9ECBFF}",{"title":30,"searchDepth":62,"depth":62,"links":2653},[2654,2655,2656,2657,2658,2659,2660,2661,2662,2663,2664,2665,2666,2667,2668,2669,2670,2671,2672,2673],{"id":20,"depth":461,"text":21},{"id":187,"depth":461,"text":188},{"id":304,"depth":461,"text":305},{"id":425,"depth":461,"text":426},{"id":587,"depth":461,"text":588},{"id":694,"depth":461,"text":695},{"id":816,"depth":461,"text":817},{"id":981,"depth":461,"text":982},{"id":1076,"depth":461,"text":1077},{"id":1179,"depth":461,"text":1180},{"id":1283,"depth":461,"text":1284},{"id":1402,"depth":461,"text":1403},{"id":1599,"depth":461,"text":1600},{"id":1797,"depth":461,"text":1798},{"id":1913,"depth":461,"text":1914},{"id":2016,"depth":461,"text":2017},{"id":2165,"depth":461,"text":2166},{"id":2311,"depth":461,"text":2312},{"id":2436,"depth":461,"text":2437},{"id":2534,"depth":461,"text":2535},"md",{},"\u002Fpython\u002F03-operators-and-expressions",{"title":5,"description":30},"python\u002F03-operators-and-expressions","CwF6upKHPbsEAhm6XhdgPsoLpv1x45YFnknAvZ0FNXI",1787335398195]