ADVERTISEMENT
ADVERTISEMENT

# Angular conversion functions in Python

Python Angular conversion functions: Here, we are going to learn about the Angular conversion functions of math module with examples in Python?
Submitted by IncludeHelp, on April 25, 2019

## Python Angular conversion functions/methods

In python programming language, there are some of the built-in functions which are defined in math module – they can be used for angular conversion i.e. to convert angle values, there are two angular conversion functions:

1. math.degrees()
It is used to convert angle value from radians to degrees.
2. math.radians()
It is used to convert angle value from degrees to radians.

Syntax of math.degrees() and math.radians() functions:

```    math.degrees(x)
math.radians(x)
```

Example:

```    Input:
x = 10.25 # value in radians

# converting & printing in degrees
x = math.degrees(x)
print(x)

# again, converting & printing in radians
x = math.radians(x)
print(x)

Output:
587.2817400090938
10.25
```

### Python code to demonstrate example of angular conversion functions

```# Python code to demonstrate example of
# math.degrees() and math.radians() methods

# importing math module
import math

# angle x in radians
x = 10.25
print("x in radians: ", x)

# converting to degrees
x = math.degrees(x)
print("x in degrees: ", x)

# now again converting to radians
x = math.radians(x)
print("x in radians: ", x)
```

Output

```x in radians:  10.25
x in degrees:  587.2817400090938
x in radians:  10.25
```

Note: If we provide anything except a number type value to these functions, they returns a TypeError.

```# Python code to demonstrate example of
# math.degrees() with exception

# importing math module
import math

# angle x in string (invalid)
x = "10.25"

# converting to degrees
x = math.degrees(x)
print("x in degrees: ", x)
```

Output

```Traceback (most recent call last):
File "/home/main.py", line 12, in <module>
x = math.degrees(x)
TypeError: a float is required
```
ADVERTISEMENT

Preparation

ADVERTISEMENT

Comments and Discussions!

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.