Cheat Sheets
Tricky Python Output Questions · Study material
Tricky Outputs Cheat Sheet
| Expression | Output |
|---|---|
-7 // 2, -7 % 2, int(-3.7) | -4, 1, -3 |
round(0.5), round(1.5), round(2.5) | 0, 2, 2 |
0.1 + 0.2 == 0.3 | False |
{1: "a", 1.0: "b", True: "c"} | {1: 'c'} |
0 or "x", [] and "y" | 'x', [] |
[] == False, not [] | False, True |
[3, 1].sort(), print("a") value | None, None |
[[0] * 2] * 2 then [0][0] = 1 | [[1, 0], [1, 0]] |
"abc"[::-1], "abc"[5:] | 'cba', '' |
a, *b = "xyz" | a='x', b=['y', 'z'] |
1 < 2 > 1.5 | True (chained) |
sorted(["bb", "a", "cc"], key=len) | ['a', 'bb', 'cc'] (stable) |