Ch 7 covers functions in depth — definition, parameters vs arguments, return values, argument types (positional, default, keyword), variable scope (local/global), and using standard library modules.
Syntax: def greet(name): return f"Hello {name}". Parameters: variables in definition. Arguments: values passed during call. Types: positional (order matters), default (def power(x, n=2) — n defaults to 2), keyword (power(n=3, x=2) — by name, order doesn't matter). Return value: return expr — sends value back to caller. Without return → None. Multiple returns: return a, b (returns tuple). Functions are first-class objects: can be assigned to variables, passed as arguments.
Scope: LEGB rule — Local (inside function) → Enclosing (outer function) → Global (module level) → Built-in. Local variables: created inside function, destroyed when function ends. Global: accessible everywhere; to modify inside function, use "global x" keyword. Built-in functions: print(), input(), len(), type(), range(), abs(), round(), min(), max(), sum(), sorted(), enumerate(). Math module: math.sqrt(), math.ceil(), math.floor(), math.pi, math.e, math.factorial(). Random module: random.randint(a,b), random.random(), random.choice(seq), random.shuffle(list).
Download: https://ncert.nic.in/textbook/pdf/kecs107.pdf | Complete Book: https://ncert.nic.in/textbook/pdf/kecs1ps.zip
Parameters are the variables listed in the function definition — they are placeholders. Arguments are the actual values passed when calling the function. Example: def add(a, b): return a+b — a and b are parameters. add(3, 5) — 3 and 5 are arguments. Think: parameters are like blanks in a form (Name: ___); arguments are the values you fill in (Name: Alice). In practice, people often use the terms interchangeably, but the distinction matters for understanding function mechanics.
Book a Trial + Diagnostic session. Get a personalized Learning Path with clear milestones, tutor match, and a plan recommendation — all within 24 hours.
Book Trial + Diagnostic →