Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 93 - 2611_SmartGPT Pro V(5.0) C-8
P. 93

    A function is a block of organised and reusable code used to perform a single or related action.
                     Functions receive data in the form of arguments and use it to run a specified set of statements
                     and produce the final output.

                               FEATURES OF FUNCTION

                     Some important features of functions are:

                        A program is divided into small modules, and each module performs a specific task. Each
                        module can be called as per the requirement.

                        We can call a function as many times as required. This saves the programmer's time and effort
                        to rewrite the same code again. Therefore, it also reduces the length of the program.
                        Dividing  a  bigger  program  into  smaller functions  makes  the  program  more  manageable.
                        It makes debugging easy and makes the code efficient, both in terms of time and memory

                        usage.

                               ADVANTAGES OF FUNCTIONS

                     Following are the advantages of functions:

                        You can write a Python program in logically independent sections.

                        Functions provide better modularity for your application and a high degree of code reusing.
                        As the program grows larger, functions make it more organised and manageable.

                        The complexity of a program can be divided into simple subtasks and function subprograms
                        can be written for every subtasks.

                        Multiple people can work on the same program by assigning different functions to each of
                        them.

                        In Python, a function can call the same function again and again, called recursiveness.

                        You could also bring in other libraries or modules to your program that contain pre-defined
                        functions readily available for use.

                               COMPONENTS OF PYTHON FUNCTION

                     A Python function consists of the following components:

                        Name of the function: A function name should be unique and easy to correlate with the task
                        it will perform. We can have functions of the same name with different parameters.

                        Parameters: These are the variables given inside the parentheses in the function definition.

                                                                                          Functions and String in Python  91

| 88 89 90 91 92 93 94 95 96 97 98 |