Page 205 - Computer Science V2.0 Class 11
P. 205

A function is a sub-program that manipulates data received as an input to solve a problem or sub-problem of a complex
                 problem and often returns one or more results. Once a function has been defined, it may be called several times from
                 different parts of the program. Subsequently, the functions are integrated to solve the complex problem.


                       The programming  methodology that focuses on organising  a computer program into smaller  manageable
                       sub-programs or modules is called modular programming.



                 8.1 Built-in Functions

                 Python provides a large number of pre-defined built-in functions such as input(), print(),  and abs().
                 Some commonly used types of built-in functions are related to input-output, data type conversion, and mathematical
                 operations. A function is invoked using the function's name followed by the sequence of arguments (separated by
                 commas) within a pair of matching parentheses. The function arguments serve as inputs to the function for performing
                 its computations. Some commonly used types of built-in functions are mentioned below:


                                         Input-Output                             Data Type Conversion
                                          Functions                                    Functions

                                          input()                                       int()
                                          print()                                       chr()
                                                                                        dict()
                                                                                        float()


                                                              Built-In Functions

                                         Mathematical                                    Other
                                           Functions                                   Functions
                                            abs()
                                            max()                                       len()
                                            min()                                        id()
                                            sum()                                      type()
                                                                                       range()
                                            pow()
                                                     Some commonly used built-in functions


                 8.1.1 Commonly used Built-in Functions

                 print()
                 As the computer screen is the default device for displaying the results, the output produced on invoking the print()
                 function is displayed on the screen.

                  >>> print('Hello')
                      Hello
                 In the above example, 'Hello'  is the argument passed to the function print(). The print() function may be
                 invoked with an arbitrary number of arguments. For example, the following function call makes use of two arguments:

                  >>> print('Hello!', 'How are you?')
                      Hello! How are you?
                 Next, we make use of print() function for displaying the value of an arithmetic expression,
                  >>> print(2+14)
                      16




                                                                                             Introduction to Functions  191
   200   201   202   203   204   205   206   207   208   209   210