Python math.atan() Method

Musfirah Waseem Jan 30, 2023
  1. Syntax of Python math.atan() Method
  2. Example Codes: Use the math.atan() Method in Python
  3. Example Codes: Enter Different Parameters in the math.atan() Method
Python math.atan() Method

Python math.atan() method is an efficient way of calculating the arctangent of a number, x, in radians.

Syntax of Python math.atan() Method

math.atan(x)

Parameters

x Any positive or negative value in the range -PI/2 and PI/2 radians.

Return

The return type of the math.atan() method is a float value representing the arctangent of x in radians.

Example Codes: Use the math.atan() Method in Python

import math

x = math.pi / 6
value = math.atan(x)
print(f"The arctangent of {x} is {value}.")

x = math.pi
value = math.atan(x)
print(f"The arctangent of {x} is {value}.")

x = math.pi / (-2)
value = math.atan(x)
print(f"The arctangent of {x} is {value}.")

Output:

The arctangent of 0.5235987755982988 is 0.48234790710102493.
The arctangent of 3.141592653589793 is 1.2626272556789118.
The arctangent of -1.5707963267948966 is -1.0038848218538872.

Note that the parameters should be in radians. The values may be either positive or negative.

Example Codes: Enter Different Parameters in the math.atan() Method

import math

x = "c"
value = math.atan(x)
print(f"The arctangent of {x} is {value}.")

Output:

Traceback (most recent call last):
  File "main.py", line 5, in <module>
    value=math.atan(x)
TypeError: must be real number, not str

Note that a TypeError exception may occur if the argument value is not a number.

Musfirah Waseem avatar Musfirah Waseem avatar

Musfirah is a student of computer science from the best university in Pakistan. She has a knack for programming and everything related. She is a tech geek who loves to help people as much as possible.

LinkedIn

Related Article - Python Math