What is Module?
In C and C++ Programming we have header files, in which we can have functions, class variables, etc. By including that header files in our code we don't write more code and reuse our functions. Same as in Python we have modules, which may have functions, classes, variables and compiled code. A module contains a group of related functions, classes, and variables.
There are three kinds of modules in python:
- Modules are written in Python(.py).
- Modules which are written in C and dynamically loaded (.dll, .pyd, .so, .sl, etc).
- Modules that are written in C but linked with an interpreter to get the list of all modules which are written in C, but linked with Python you can use the following code.
- import sys
- print(sys.builtin_module_names)
Output:
('_ast', '_bisect', '_codecs', '_codecs_cn', '_codecs_hk', '_codecs_iso2022', '_codecs_jp', '_codecs_kr', '_codecs_tw', '_collections', '_csv', '_datetime', '_functools', '_heapq', '_imp', '_io', '_json', '_locale', '_lsprof', '_md5', '_multibytecodec', '_opcode', '_operator', '_pickle', '_random', '_sha1', '_sha256', '_sha512', '_sre', '_stat', '_string', '_struct', '_symtable', '_thread', '_tracemalloc', '_warnings', '_weakref', '_winapi', 'array', 'atexit', 'audioop', 'binascii', 'builtins', 'cmath', 'errno', 'faulthandler', 'gc', 'itertools', 'marshal', 'math', 'mmap', 'msvcrt', 'nt', 'parser', 'signal', 'sys', 'time', 'winreg', 'xxsubtype', 'zipimport', 'zlib').
Python Math Module
You can see in the above list, the math module is written in C programming but linked with Interpreter that contains Math functions and variables. which we will discuss in this article.
Number Representational Function
Ceil and floor function
Ceil and floor functions are common functions. The
ceil function rounds up the number to the next highest one. The
floor function removes digits decimal points. Both functions take a decimal number as argument and return an integer.