AppDividend
Latest Code Tutorials

# Python atanh() Function | Math.atanh() in Python Example

Python atanh() is an inbuilt method defined under the math module, which is used to find the hyperbolic arctangent of the given argument in radians. For example, if x is passed as the parameter in atanh Function (atanh(x)), it returns the hyperbolic arctangent value. We can use a math module by importing it. Another important point to note is that math atanh() function only takes parameter values of number type if any other type is passed; it returns type error.

## Python atanh()

Content Overview

Python math.atanh() method is a library method of the math module, and it is used to get the hyperbolic arctangent of the given number in radians, it accepts a number and returns hyperbolic arctangent.

### Syntax

```math.atanh(var)
```

Here var is a variable of which hyperbolic tangent arc we have to find.

### Parameters

It takes one parameter var, which takes values of numeric datatype and throws TypeError if an argument is of any other data type is passed.

### Return Value

It returns a hyperbolic arctangent value of the number in the float datatype.

See the following code.

```import math

var = 0.6
print(math.atanh(var))
```

### Example programs on atanh() method in Python

#### Example 1: Write a program to show the working of the atanh() method in Python.

```import math

a1 = 0.7
b1 = 0.99
c1 = 0.35
d1 = 0.55

print("Value for parameter ", a1, " is ", math.atanh(a1))
print("Value for parameter ", b1, " is ", math.atanh(b1))
print("Value for parameter ", c1, " is ", math.atanh(c1))
print("Value for parameter ", d1, " is ", math.atanh(d1))
```

#### Output

```Value for parameter  0.7  is  0.8673005276940532
Value for parameter  0.99  is  2.6466524123622457
Value for parameter  0.35  is  0.3654437542713961
Value for parameter  0.55  is  0.6183813135744636
```

In this example, we have seen that by passing the valid parameter which is different for different examples, we get the desired atanh() method solution, which is the hyperbolic tangent value of the parameter.

#### Example 2: Write the program to pass a value out of range from the atanh() Function and display the output.

See the following code.

```import math

q = "H"
print(math.atanh(q))
```

#### Output

`TypeError: must be a real number, not str`

In this example, we’ve seen that by passing a parameter which is not of number type, the Function throws an error.

## Python atanh() with list and tuple

Python asinh() function allows you to find a Trigonometric Hyperbolic ArcSine of the numeric values. Let’s use with Python list and tuple.

```# app.py

import math

Tup = (21, 11, 19, -46, 30)
Lis = [-15, 25, -32.5, -45.95, 15.64]

print('Python Hyperbolic Arc Sine of Positive Number = %.2f' % math.asinh(21))
print('Python Hyperbolic Arc Sine of Negative Number = %.2f' % math.asinh(-11))

print('Python Hyperbolic Arc Sine of Tuple Item = %.2f' % math.asinh(Tup))
print('Python Hyperbolic Arc Sine of List Item = %.2f' % math.asinh(Lis))

print('Python Hyperbolic Arc Sine of Multiple Numbers = %.2f' %
math.asinh(22 + 49 - 27))

print('Python Hyperbolic Arc Sine of String Value = ', math.asinh('Hello'))
```

#### Output

```python3 app.py
Python Hyperbolic Arc Sine of Positive Number = 3.74
Python Hyperbolic Arc Sine of Negative Number = -3.09
Python Hyperbolic Arc Sine of Tuple Item = -4.52
Python Hyperbolic Arc Sine of List Item = -4.17
Python Hyperbolic Arc Sine of Multiple Numbers = 4.48
Traceback (most recent call last):
File "app.py", line 15, in <module>
print('Python Hyperbolic Arc Sine of String Value = ', math.asinh('Hello'))
TypeError: must be real number, not str```

First, we used the asinh Function directly on both the Positive integer and negative integer. The following statements find the hyperbolic arcsine of the corresponding values.

Next, We used the asinh() Function on Tuple and List items. If you observe the above output, the asinh() function is working correctly on them.

At last, we have passed asinh() Function on the string value, and it returns TypeError as output.