Skip to main content

Diving into Modules - Math Module

 >Math Module - Overall explanation


Source: freepik


Introduction

Other than Python built-in functions, there are numerous functions which can be found in some packages which need to be imported when needed which are called modules

Such a module in python is the math module. Python's standard library provides a module viz. math for math functions that work with all number types except complex numbers.
The Math module in Python is enriched with plenty of functions.

Note!: To use the math module one must import it first into the Python compiler one has been working with. The syntax to do so is given below:

import math


FUNCTIONS IN MATH MODULE


ceil(): This function returns the closest just above integer when a value has been passed.

Syntax:
x = math.ceil(2.4)
print(x)
floor(): This function returns the closest just below integer when a value has been passed.

Syntax:
y = math.floor(2.4)
print(y)
fabs(): This function returns the absolute number in floats when a negative or positive value has been passed in float or integer form.

Syntax:
print(math.fabs(2.4))
print(math.fabs(-6.8))
print(math.fabs(-27))
print(math.fabs(78))

More functions based on this module will be continued in a later blog post...

©SGPython

Comments

Popular posts from this blog

Our view towards Python (as a programming language)

  Python - The language of the future Introduction When we hear the term programming language, we usually talk about high-level programming language which are those programming language having a lucid (or easy-to-read) syntax and are later converted to low-level language (binary) , which is understandable by the computer.  Programming language has always been an area of interest over the passing years since the very early days of ' Fortran ' (created by John Backus at  IBM ). To this day, dozens of programming language has been created by different 'Computer Scientists' around the world. What is Python? What is Python? Many of you will describe a large scary snake 🐍, which isn't actually wrong 😅. But here we are talking about a programming language. Similarly, Python is also a high-level and interepreted programming language created by  Guido van Rossum in the late 1980s . It was first released in 1991 as a successor to ABC Programming language . It known fo...

For Loops

 The for loop By  polygraphus  on  shutterstock Def: The for loop is also known as the counting loop and is designed to process the items of any sequence, such as a list or a string, one by one. General form of for loop: The general form of the for loop is given below:      for <variable> in <sequence>:          statements to repeat

Type-Casting And Dynamic-Typing

Python is equipped with some of the amazing and easy to use methods which are already built-in keeping the ease of understanding and fun-to-learn. Some of these amazing properties are going to be discussed today in the blog. Type-Casting Typecasting is one of the simple topics of Python which which is very much easy to understand yet is very efficient in the day-to-day lives of Python programmers. Def:  The explicit conversion of an operand to a specific type is called  typecasting. Explicit conversion refers to the type of conversion of datatype into which the user wants to change his or her expression into. Note that these types of conversion are user defined. Typecasting in Python can be explained as follows:                         <datatype> (expression) where <datatype> refers to the datatype into which the user wants to type-cast. Example:  When we use input() function, Python alwa...