Working with Functions
CBSE Class 12 Computer Science
Pradnya's Class
Page 1
What is a Function?
A function is a subprogram that acts on data and often returns a value.
Functions promote modularity, readability, reusability, and manageable code.
Page 2
Advantages of Functions
- Breaks big problems into smaller ones
- Avoids ambiguity
- Reduces code size
- Improves readability and enhances reusability
Page 3
Arguments vs Parameters
- Parameters: Placeholders in function definitions (formal)
- Arguments: Actual values passed during function calls (actual)
Page 4
Types of Parameters
- Positional (required): Matched by position
- Default parameters: Predefined values
- Keyword (named): Passed by name, order does not matter
Page 5
Structure of a Function
- Header: def name(params):
- Body: Indented statements
- Optional return statement
- Call using name(args)
Page 6
Function Types
- Void functions: No return value
- Non-void functions: Return a value
- Built-in functions: Already available
- Module functions: From imported modules
- User-defined functions: Created by the user
Page 7
Parameter Passing Basics
- Mutable vs Immutable
- Scope: Local vs Global variables
- Use of global keyword
Page 8
Code Examples
- Example of positional, default, and keyword arguments
- Void vs return-value functions
- Global scope variable usage example
Page 9
Summary & Key Takeaways
- Functions make code reusable and organized
- Understand parameter types and scopes
- Practice with different examples and use cases
Page 10