๐Ÿ”ฅ 75% OFF Early-bird โ‚น2,999 one time โณ BOARDS ARE CLOSE Lock this price before it goes up. Grab my seat โ†’
Subjects โ€บ Computer Science โ€บ Functions

Functions

๐Ÿ”’ Priority & marks: full access ยท 31 questions shown
๐Ÿ“Œ 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.