Basic HTML Version

|  | Table of Contents |  | View Full Version

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

    Statements: The statements are the executable instructions that the function can perform.

                          Return Value: A function may or may not return a value.

                                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 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 needs 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  the  parameters  and
                      return type. The functions that do not take any parameter or return anything are called type 1
                      functions.

                      The type  2 functions  take  parameters  but  do  not  return anything.  The type  3 functions  take
                      parameters and return a value.

                                               1.  Write any two components of Python function.
                              uiz    Bee          _____________________________________________________________

                                               2.  What is the main difference between built-in and user-defined functions?

                                                  _____________________________________________________________

                                CREATING A FUNCTION

                      We can create a function in the following ways
                          Defining a Function: We use the def keyword to begin the function definition.

                          Naming a Function: Provide a meaningful name to your function.

                          Supply Parameters: The parameters (separated by commas) are given in the parenthesis
                         following the name of the function. These are basically the input values we pass to the
                         function.

                       92   Computer Science (V5.0)-VIII

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