๐ This question is part of the full practice set
Start free โ 5 days
Subjects โบ Computer Science โบ Functions
Functions
๐ How to approach this chapter
In a typical paper this chapter carries about 5.2 marks. Mostly output prediction and parameter rules.
- What the questions look like: output of a function with default arguments, positional vs default parameters, scope (local vs global), "what happens if...", and 2-3 mark "write a function that ...".
- Default parameters must come after non-default ones (def f(a, b=1) is valid, def f(a=1, b) is a SyntaxError). Positional arguments are matched in order; keyword arguments by name.
- A function without return gives None. return a, b returns one tuple. Code after return is never executed.
- Scope: a variable assigned inside a function is local unless declared global. Reading a global inside a function is fine; assigning without "global" creates a new local (or UnboundLocalError if read first).
- Mutable arguments (list, dict) can be changed inside a function and the caller sees the change; immutable ones (int, str, tuple) cannot.
- Know the common built-ins and modules: len, type, max, min, sum, sorted; math.sqrt/pow/ceil/floor; random.randint; statistics.mean/median.
You can try the first few questions here. Start free for 5 days to open everything.
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days
๐ This question is part of the full practice set
Start free โ 5 days