Python Modules:
Modules are the files in python used for grouping similar codes, to get an easy access to those codes. Python Modules facilitates reusability and easy categorization of codes.
Python Built In Modules:
Python facilitates its users a variety of modules already defined in Python library that makes Python a easy to use programming language. Some of these modules are:
Python Math Module:
Python math module contains different built in mathematical functions and mathematical constants.
Math Functions:
FUNCTION | USES |
ceil() | To get the next integer number of the given number. |
sqrt() | To get the Square root of the given number. |
exp() | To get the natural logarithm e raised to the given number. |
floor() | To get the previous integer number of the given number. |
log() | To get the natural logarithm of the number. |
pow() | To get base_to raised to the exp power. |
sin() | To get the sine of the given angle in radian. |
cos() | To get the cosine of the given angle in radian. |
tan() | To get the tangent of the given angle in radian. |
Math Constants:
CONSTANTS | VALUES |
pi | 3.14159… |
e | 2.71828… |
Python Random Module:
Python random module contains different built in functions to generate random numbers.
FUNCTION | USES |
random() | To get a random number between 0.0 and 1.0 where 1.0 is exclusive. |
randint(x,y) | To get a random number between x and y where both the numbers are inclusive. |
Importing a Python Module:
Python modules can be imported in three ways, using:
Python import statement:
Python “import” statement is used to import a Python module.
Python from.. import statement:
Python also facilitates to import a specific attribute from a Python module. This can be done using Python “from..import” statement.
Python from.. import* statement:
Python “from..import*” statement is used to import a complete Python module.