Computer science
Functions in programming are groups of related statements that perform specific tasks
Help in dividing a large program into smaller, more manageable chunks
Example: Creating functions for drawing circles, rectangles, and coloring shapes based on user input
Creating a function in Python
Use the
defkeyword followed by the function name and a colonNeed to define the function before calling it
Chapter 2: Call The Function
Calling a function in Python
Use the function name followed by empty parentheses to call it
Function body executes when the function is called
Functions can be called multiple times
Allows for performing a task repeatedly by calling the function again
Chapter 3: The Great Function
Importance of defining a function before using it
Introduction to Python arguments
Passing values (arguments) to a function
Example: Passing a name to the greet function to make it more personal
Chapter 4: Inside The Function
Passing multiple arguments to a function by separating them with commas
Using the
returnstatement to return a value from a functionControl of the program returns to the calling point when a
returnstatement is encountered
Chapter 5: Create A Function
User-defined functions are functions created by the programmer
Example of creating a function to add two numbers and using the
returnstatement to return the resultControl of the program returns to the calling point after encountering a
returnstatement
Chapter 6: Sum Of Marks
Print function is a built-in function in Python
Defined within Python programming language
Makes it easy to display output
Built-in functions in Python
Examples: float, int, input
Numerous built-in functions available
Using built-in functions
Example: finding length of a list using
len()Example: finding sum of items in a list using
sum()
Accessing built-in functions
Available on programiz.com
Applying learned concepts
Chapter 7: Great Average Marks
Problem scenario: finding average marks and determining grade
Creating functions
Function to find average marks
Parameters: list of marks
Calculating average marks
Function to compute grade
Parameters: average marks
Determining grade based on rules
Implementing functions
Calculating average marks and grade
Displaying results
Chapter 8: Call The Function
Programming task: adding and multiplying 2 numbers
Creating functions
add_numbers()andmultiply_numbers()Computing and returning results
Accessing results outside functions
Resources on GitHub and programiz.com
Chapter 9: Conclusion
Functions in Python
Defined using
defkeywordCalling functions to execute tasks
Passing values to functions
Arguments or parameters
Return statement
Returns value from function and exits
Encouragement to practice coding