0% found this document useful (0 votes)
4 views3 pages

Class12 CS Working With Functions Notes

This document provides comprehensive notes on functions in computer science, covering their definition, types, syntax, and key concepts such as parameters, return statements, and recursion. It includes examples of built-in and user-defined functions, as well as details on variable scope and lambda functions. Additionally, it offers tips for effectively working with functions.

Uploaded by

haruvijay4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Class12 CS Working With Functions Notes

This document provides comprehensive notes on functions in computer science, covering their definition, types, syntax, and key concepts such as parameters, return statements, and recursion. It includes examples of built-in and user-defined functions, as well as details on variable scope and lambda functions. Additionally, it offers tips for effectively working with functions.

Uploaded by

haruvijay4
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Class 12 Computer Science - Working with Functions (Full Notes)

WORKING WITH FUNCTIONS - FULL NOTES

1. What is a Function?
- A function is a reusable block of code that performs a specific task.
- Helps reduce redundancy and makes code more readable.

2. Types of Functions
- Built-in Functions: Predefined (e.g., print(), len(), input(), type())
- User-defined Functions: Created by the programmer using def

3. Defining a Function
Syntax:
def function_name(parameters):
statements
return value

Example:
def greet(name):
print("Hello", name)

4. Calling a Function
- Just use the function name with arguments: greet("Haru")

5. Parameters and Arguments


- Parameters: variables listed in function definition
- Arguments: values passed during function call

6. Return Statement
- Used to return a value from a function
- Ends the execution of the function

Example:
def add(a, b):
return a + b
7. Default Parameters
- Parameters with default values
Example:
def greet(name="User"):
print("Hello", name)

8. Keyword and Positional Arguments


- Positional: matched by position
- Keyword: matched by name

Example:
def student(name, age): pass
student(age=17, name="Haru")

9. Variable Scope
- Local Scope: Defined inside function
- Global Scope: Defined outside function

global x
x=5
def show():
global x
x=x+1

10. Recursion
- Function that calls itself
- Must have a base condition to end recursion

Example:
def factorial(n):
if n == 1:
return 1
return n * factorial(n - 1)

11. Lambda Functions


- Small anonymous functions
Syntax: lambda arguments: expression
Example:
square = lambda x: x*x
print(square(5)) # Output: 25

Tips:
- Always trace recursive functions.
- Use return wisely.
- Know the difference between arguments and parameters.
- Use local/global properly.

You might also like