hardPythonkeyword-only args
What will this code output?
def f(x, y, /, z=10):
return x + y + z
print(f(1, 2))Read the full question →Hard questions live in the specification: evaluation order, memory and lifetime, coercion corners, and the behaviour that only shows up under concurrency.
Aimed at senior screens and at anyone who wants to stop being surprised by their own language.
Expect snippets that look wrong but are correct, or look correct and are not. Reading the explanation matters more here than getting it right.
Eighteen real hard questions from across the library, code snippet included. The answer options and explanations come after you attempt them.
def f(x, y, /, z=10):
return x + y + z
print(f(1, 2))Read the full question →from dataclasses import dataclass
@dataclass
class A:
items: list = []
a1 = A()
a2 = A()
a1.items.append(1)
print(a2.items)Read the full question →try:
raise ValueError("oops")
except Exception:
print("General")
except ValueError:
print("Value")Read the full question →class A:\n def __call__(self): return 2\nprint(A()())Read the full question →const arr: number[] = [1,2,3];\nconst x = arr[0]; // with noUncheckedIndexedAccessRead the full question →type X = `${Capitalize<"foo">}Bar`;Read the full question →type X = string & number;Read the full question →const f = (x: number) => x + 1;Read the full question →class A:\n v = "x"\na = A()\na.v = "y"\nprint(a.v)Read the full question →console.log([] == false);Read the full question →// legacy pattern
const [snap, setSnap] = useState(store.getSnapshot());
useEffect(() => {
const unsub = store.subscribe(() => setSnap(store.getSnapshot()));
return unsub;
}, []);Read the full question →a, b = 256, 256\nc, d = 257, 257\nprint(a is b, c is d)Read the full question →const o = { x: "b", f() { return this.x; } };\nconsole.log(o.f());Read the full question →const x = 1;\nx = 2;Read the full question →print("hello" + 5)Read the full question →print("".join(print("hi")))Read the full question →class A { #x = 1; getX() { return this.#x; } }\nconsole.log(new A().getX());Read the full question →type X = Exclude<"a"|"b","a"|"b">;Read the full question →