create account

Working With Python Math Module - Part 2 by leoumesh

View this thread on: hive.blogpeakd.comecency.com
· @leoumesh ·
$35.85
Working With Python Math Module - Part 2
<div class="text-justify">

![image.png](https://images.hive.blog/DQmQxuUaCNhiXAotqYVWSRHU7fjTyXj9ibgWnbQhKrSpGGm/image.png)
<center>[Image Source](https://levelup.gitconnected.com/learn-the-python-math-module-9c2c516ea37c)</center>

In my last post, I wrote about the basic introduction of the math module in python programming and also discuss about some basic functions to perform certain mathematics operation. In this post, we will see about the some other functions in the same module. Lets use `dir()` function to see the list of funtions within our math module. We will use for loop to iterate over each loop.

```
for i in dir(math):
    print(i)
```

You can see the following output while executing the above code. These are the list of functions provided by the math module that you can use for performing certain operations. You can see a lot of other functions as well when you scroll down the output window.

![image.png](https://images.hive.blog/DQmf6krscwLXFHP8AoJQTjiHDPu4B2AQ4b26eARGCqN4p7k/image.png)

We know lists, tuples and arrays are important data structures in python. One of the function that is provided by math module is `fsum()` that returns the sum of all items in these iterables. For example `print(math.fsum([4, 6, 8, 3]))` will return output as 21 as below:


![image.png](https://images.hive.blog/DQmQB2WM8JHMamkEotbtyfPXoW5WjuGdH4HnytbxMT5uXi4/image.png)

In the same way you can use `prod()` to find the product of items in lists, tuples or arrays. For example you can use this syntax `print(math.prod([2, 4, 5]))` to find the product of all numbers in a list. The outuput should be 40 in this case and same can be seen below.


![image.png](https://images.hive.blog/DQmTMiRkbM5JFDc6DfreDzyyzWCUNbfSxreoBVKCUorMM4Q/image.png)

Also you can use this module for performing trigonometric operations. Lets try to find the value of  cosπ which is -1. In python it can be done using the following syntax: `print(math.cos(math.pi))`. Following output can be seen in execution.


![image.png](https://images.hive.blog/DQmWf56j9LyKG4w1ecQ7xkKLvEcydF7w1ovVDb5AR3LnGJW/image.png)

In the same way you can use `tan()` function to find the tangent value of any number. We know  tan 45° is 1. In following code we will express 45° as (π/4) and see the same output. The code is:

```
a = math.pi/4

print(math.tan(a))
```
The output is:

![image.png](https://images.hive.blog/DQmReXDWNfwgnp6BTsLTGy8he59hgKWKXJ8ZpX5HiTbnFeA/image.png)

Apart from these stuffs, you can use math module to perform logarithmic operations, hyperbolic functions (trigonometric functions on hyperbolas), other special operations like finding Gaussian value, Euclidean distance and so on.


</div>
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 57 others
properties (23)
authorleoumesh
permlinkworking-with-python-math-module-9de51d73b9e7c
categoryhive-163521
json_metadata{"links":["https://levelup.gitconnected.com/learn-the-python-math-module-9c2c516ea37c"],"image":["https://images.hive.blog/DQmQxuUaCNhiXAotqYVWSRHU7fjTyXj9ibgWnbQhKrSpGGm/image.png","https://images.hive.blog/DQmf6krscwLXFHP8AoJQTjiHDPu4B2AQ4b26eARGCqN4p7k/image.png","https://images.hive.blog/DQmQB2WM8JHMamkEotbtyfPXoW5WjuGdH4HnytbxMT5uXi4/image.png","https://images.hive.blog/DQmTMiRkbM5JFDc6DfreDzyyzWCUNbfSxreoBVKCUorMM4Q/image.png","https://images.hive.blog/DQmWf56j9LyKG4w1ecQ7xkKLvEcydF7w1ovVDb5AR3LnGJW/image.png","https://images.hive.blog/DQmReXDWNfwgnp6BTsLTGy8he59hgKWKXJ8ZpX5HiTbnFeA/image.png"],"tags":["hive-163521","stem","math","mathematics","python","coding","programming","tutorial","function"],"app":"ecency/3.0.23-mobile","format":"markdown+html"}
created2021-12-12 03:25:30
last_update2021-12-12 03:25:30
depth0
children0
last_payout2021-12-19 03:25:30
cashout_time1969-12-31 23:59:59
total_payout_value17.964 HBD
curator_payout_value17.883 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,698
author_reputation212,340,493,251,438
root_title"Working With Python Math Module - Part 2"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id108,477,447
net_rshares18,262,548,902,607
author_curate_reward""
vote details (121)