Home » Python

math.atan() method with example in Python

Python math.atan() method: Here, we are going to learn about the math.atan() method with example in Python.
Submitted by IncludeHelp, on April 21, 2019

Python math.atan() method

math.atan() method is a library method of math module, it is used to get the arc tangent, it accepts a number and returns the arc tangent value (in radians) of the given number.

Note: math.atan() method accepts the only number, if we provide anything else except the number, it returns error TypeError - "TypeError: a float is required".

Syntax of math.atan() method:

    math.atan(x)

Parameter(s): x – is the number whose arc tangent to be calculated.

Return value: float – it returns a float value that is the arc tangent value of the number x.

Example:

    Input:
    a = 0.278

    # function call
    print(math.atan(a))

    Output:
    0.27115314223853704

Python code to demonstrate example of math.atan() method

# python code to demonstrate example of 
# math.atan() method 

# importing math module
import math

# number
a = -1
print("atan(",a,") is = ", math.atan(a))

a = 0
print("atan(",a,") is = ", math.atan(a))

a = 0.278
print("atan(",a,") is = ", math.atan(a))

a = 1
print("atan(",a,") is = ", math.atan(a))

a = 123
print("atan(",a,") is = ", math.atan(a))

Output

atan( -1 ) is =  -0.7853981633974483
atan( 0 ) is =  0.0
atan( 0.278 ) is =  0.27115314223853704
atan( 1 ) is =  0.7853981633974483
atan( 123 ) is =  1.5626664246149526

TypeError example

# python code to demonstrate example of 
# math.atan() method with an exception

# importing math module
import math

# number
a = "2"
print("atan(",a,") is = ", math.atan(a))

Output

Traceback (most recent call last):
  File "/home/main.py", line 9, in <module>
    print("atan(",a,") is = ", math.atan(a))
TypeError: a float is required


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.