Page 114 - Plus V4 with Adobe class 8
P. 114

Types of Functions in Python

        We have mentioned earlier that one of the strengths of the Python language is that Python functions
        are easy to define  and use. Python functions  can be categorised into  built-in functions  and
        user-defined functions. Let us discuss about them in detail.

        Built-in Functions

        The print() and input() belong to the category of built-in functions. We also have other built-in functions
        like range(), type(), etc. The main difference between these two categories is that built-in functions do
        not require to be written by us, whereas a user-defined function has to be developed by the user at the
        time of writing a program.

        User-defined Functions

        User-defined functions are created by the user according to the need of the program. Once the user
        defines a function, the user can call it in the same way as the built-in functions. User-defined functions
        are divided into various categories based on their parameters and return type. The functions that do
        not take any parameters and do not return any values are called type 1 functions.

        Type 2 functions take parameters but do not return anything. Type 3 functions take parameters and
        return values. Let us understand this with the help of an example:

          Program 2: To add two numbers using all the three types of user-defined functions.




























        You will get the following output:



















            112  Plus (Ver. 4.0)-VIII
   109   110   111   112   113   114   115   116   117   118   119