GRUEN INTERNATIONAL SCHOOLS, PORT HARCOURTA function is a named, reusable block of code designed to perform a particular task. Functions reduce repetition, improve organization and make programs easier to test and maintain.
Example: def greet(name):
Print(“hello, welcome to programming!)
Parameters are variables listed in a function definition. Arguments are the actual values supplied when the function is called.
A return statement sends a result back to the calling part of a program. A function may return a value or simply perform an action.
Built-in functions are supplied by the language, such as len(), max() and sum() in Python. User-defined functions are created by the programmer.
Functions promote code reuse, modularity, readability, easier debugging and easier maintenance.
An array/list stores multiple related values under one variable name. In Python, a list is an ordered and changeable collection, for example scores = [65, 72, 81, 90].
Python uses zero-based indexing, so the first element has index 0. Common list operations include accessing an item, changing an item, append() to add an item, remove() to delete a matching item and len() to obtain the number of items.
A function can receive a list and process its elements with a loop. For example, a function can calculate the total or average of students' scores.
Breaking a problem into functions and choosing an appropriate data structure makes a program easier to understand and maintain.