Page 160 - CodePilot V5.0 C8
P. 160

SHORT SIGN

                                                                                                  To get auto
                      The ‘+’ operator when used with lists needs both the operands           completion in IDLE:
                           to be of list type, otherwise it will produce an error.                Ctrl + space






                         LIBRARIES IN PYTHON


                  A library is a collection of prewritten code for specific functions. In Python, a library is a
                  set of interconnected modules. A module is a Python file containing functions, classes and
                  variables that can be reused across multiple programs, making code modular and easier
                  to manage.

                  Following are the advantages of using Libraries:

                      Saves time: No need to build everything from scratch.

                      Reusability: Achieve more with fewer lines of code, improving modularity.

                      Simplifies  complex tasks:  Users can  call tested  and  optimised  methods  without  knowing
                     internal details.


                  IMPORTING A MODULE

                  A library contains multiple interrelated modules. To use the functionality of a module, you must
                  import it using the import statement. The syntax is as follows:

                  import module_name


                  MATH MODULE
                  Python’s math module provides a wide range of functions for mathematical operations. Some of

                  the most commonly used methods include:

                      math.ceil(): It rounds a number up to the nearest integer.
                      math.factorial(): It returns the factorial of a positive integer.

                      math.floor(): It rounds a number down to the nearest integer.

                      math.fmod(): It returns the floating-point remainder when x is divided by y.

                      math.gcd(): It returns the greatest common divisor of two integers.

                      math.pow(): It returns the value of x to the power of y.

                      math.sqrt(): It returns the square root of a number.

                  The math module must be imported before its functions can be used.




                   158
                        CodePilot (V5.0)-VIII
   155   156   157   158   159   160   161   162   163   164   165