Which function is used to convert an angle from radians into degrees in python?

View Discussion

Improve Article

Save Article

  • Read
  • Discuss
  • View Discussion

    Improve Article

    Save Article

    degrees() and radians() are methods specified in math module in Python 3 and Python 2. 
    Often one is in need to handle mathematical computation of conversion of radians to degrees and vice-versa, especially in the field of geometry. Python offers inbuilt methods to handle this functionality. Both the functions are discussed in this article.

    radians()

    This function accepts the “degrees” as input and converts it into its radians equivalent. 
     

    Syntax : radians(deg) Parameters : deg : The degrees value that one needs to convert into radians Returns : This function returns the floating point radians equivalent of argument. Computational Equivalent : 1 Radians = 180/pi Degrees.

      Code #1 : Demonstrating radians() 

    Python3

    import math

    print("180 / pi Degrees is equal to Radians : ", end ="")

    print (math.radians(180 / math.pi))

    print("180 Degrees is equal to Radians : ", end ="")

    print (math.radians(180))

    print("1 Degrees is equal to Radians : ", end ="")

    print (math.radians(1))

    Output:

    180/pi Degrees is equal to Radians : 1.0
    180 Degrees is equal to Radians : 3.141592653589793
    1 Degrees is equal to Radians : 0.017453292519943295

    degrees()

    This function accepts the “radians” as input and converts it into its degrees equivalent. 
     

    Syntax : degrees(rad) Parameters : rad : The radians value that one needs to convert into degrees. Returns : This function returns the floating point degrees equivalent of argument. Computational Equivalent : 1 Degrees = pi/180 Radians.

      Code #2 : Demonstrating degrees() 

    Python3

    import math

    print("pi / 180 Radians is equal to Degrees : ", end ="")

    print (math.degrees(math.pi / 180))

    print("180 Radians is equal to Degrees : ", end ="")

    print (math.degrees(180))

    print("1 Radians is equal to Degrees : ", end ="")

    print (math.degrees(1))

    Output:

    pi/180 Radians is equal to Degrees : 1.0
    180 Radians is equal to Degrees : 10313.240312354817
    1 Radians is equal to Degrees : 57.29577951308232

    Application : There are many possible applications of these functions in mathematical computations related to geometry and has a certain applications in astronomical computations as well.


    Mathematically we are all familiar with radians and degrees. Radians are something that intercepts an arc on the circle equal in length. A degree is a unit of the angle of measurement. And we also know that how to convert the radians to degrees. Now let us think about how to implement it in python. There are four unique ways available to convert radians to degrees in python. In this article, we will learn all the four possible ways.

    A complete revolution of a circle in anticlockwise is represented by 2π in radians, and we can describe it in degree as 360o. Based on this statement, we can define the equation as 2π=360o. And also π=180o. So from this, we can easily say that π radian is equal to 180 degrees. 

    Methods to convert radians to degrees:

    • Normal method using formula
    • Using degrees() function
    • By numpy.degree()
    • Using np.rad2deg()

    • Method 1: Using the formula to convert radians to degrees in python
      • Code to convert radians to degrees in python
    • Method 2: Using degrees() function to convert radians to degrees in python
      • Syntax
      • Parameter
      • Returns
      • Code to convert radians to degrees in python
    • Method 3:Using numpy.degrees() to convert radians to degrees in python
      • Syntax
      • Parameters
      • Returns
      • Code
    • Method 4: Using np.deg2rad to convert radians to degrees in python
      • Syntax
      • Parameters
      • Returns
      • Code
    • Bonus section: How to convert degrees to radians
      • Code
    • FAQs Related to Radians to Degrees Conversion in Python
    • Conclusion
    • Trending Right Now

    Method 1: Using the formula to convert radians to degrees in python

    There is a standard method available to convert radians to degrees using a formula. We can implement this method by function. The conversion formula is:

    Degree = (Radian X π )/180

    Code to convert radians to degrees in python

    import math
    def degree_converter(x):
        pi_value=math.pi
        degree=(x*180)/pi_value
        return degree
    print("The degree of the given radian is :",degree_converter(1.5708))
    

    Import math. Create a function named degree, including a pi value. I am using the above-given formula to calculate the degree of the given radian. Return the value of the degree.

    Output

    The degree of the given radian is : 90.0002104591497

    Which function is used to convert an angle from radians into degrees in python?

    Method 2: Using degrees() function to convert radians to degrees in python

    degrees() is a built-in function that is already available in python. This will convert the given radians into degrees.

    Syntax

    math.degrees(radian value)

    Parameter

    Radian value: input radian values

    Returns

    Degree of the given radian value

    Code to convert radians to degrees in python

    import math 
    radians = 1.5708
    degrees = math.degrees(radians)
    print("The degree of the given radian is :",degrees)
    

    Import a math function. Use the built-in function to get the degrees of the given radian. Print the degrees.

    Output

    The degree of the given radian is: 90.00021045914971

    Method 3:Using numpy.degrees() to convert radians to degrees in python

    We can also use the numpy module to convert the radians to degrees. numpy.degrees() is a function that is useful to get the degrees of the given radians. This is one of the built-in functions in the numpy module.

    Syntax

    numpy.degrees(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'degrees'>

    Parameters

    • x: Input radian
    • out: A memory to store the result
    • where: array-like
    • **kwargs: For other keyword-only arguments, see the ufunc docs.

    Returns

    Degree value of the given radian

    Code

    import numpy
    radian = 1.5708 
    degrees=numpy.degrees(radian)
    print("The degree of the given radian is:",degrees)
    

    Import a numpy module. Declare a variable radian. Assign a value for the radian variable. Use the numpy.degrees() function. Print the value of the degrees.

    Output

    The degree of the given radian is: 90.00021045914971

    Method 4: Using np.deg2rad to convert radians to degrees in python

    In numpy, there is another function available to convert the radian to degrees. That is np.rad2deg function. This is a function available in the numpy module.

    Syntax

    numpy.rad2deg(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'rad2deg'>

    Parameters

    • x: Input radian
    • out: A memory to store the result
    • where: array-like
    • **kwargs: For other keyword-only arguments, see the ufunc docs.

    Returns

    Degrees of the given radian

    Code

    import numpy as np
    radian = 1.5708 
    degrees=np.rad2deg(radian)
    print("The degree of the given radian is :",degrees)
    

    Import a numpy module as np. Give an input radian. Use the np.rad2deg function. Print the degree.

    Output

    The degree of the given radian is : 90.00021045914971

    Bonus section: How to convert degrees to radians

    So far, we have entirely learned how to convert the radian values to degrees. As additional knowledge, we will learn the reverse process, that is, degrees to radians. We will now know how to get the radians for the values of the given degree. We will use math.radians() function to get the radians of the given values.

    Code

    import math 
    degrees = 90
    radians = math.radians(degrees)
    print("The radian value is:",radians)
    

    Import a necessary module. Here we need to import a math module. Give the input degrees. Use the radians() function to get the radians. This function will return the radian value for the given degree. Print the result.

    Output

    The radian value is: 1.5707963267948966

    Which function is used to convert an angle from radians into degrees in python?

    1. How many possible ways are there to convert the radians to degrees in python?

    There are four possible ways to convert the radians to degrees in python namely, math.degrees(), numpy.degree(), numpy.rad2degree() and custom function.

    2. What are the ways to convert the radians to degrees?

    We can convert the radians to degrees by a normal method using the formula, degrees() function, numpy.degrees(), and np.rad2deg() function.

    3. How to print degree sign in python?

    degree_symbol= u’\N{DEGREE SIGN}’
    print(degree_symbol)

    Conclusion

    In this article, we have learned how to get the degree value by using radian values in python. Learn all the four methods to get the degree values. While learning something, try to know all the possible ways. That is the way to become a good programmer. Try to solve the programs on your own.

    In case of any queries, let us know in the comment section. We will help you. Learn python with us. Shine in your way. Happy coding.

    • Which function is used to convert an angle from radians into degrees in python?

      How To Solve Error: legacy-install-failure?

      September 6, 2022

    • Which function is used to convert an angle from radians into degrees in python?

      6 Methods To Tokenize String In Python

      by Yugmil PatelSeptember 6, 2022

    • Which function is used to convert an angle from radians into degrees in python?

      [Solved] Easily Overflowerror: Math Range Error

      by Yugmil PatelAugust 19, 2022

    • Which function is used to convert an angle from radians into degrees in python?

      Recommended Ways to Print To Stderr in Python

      by Yugmil PatelAugust 19, 2022

    How do you convert radians to degrees in Python?

    Python Math: Convert radian to degree.
    Sample Solution:-.
    Python Code: pi=22/7 radian = float(input("Input radians: ")) degree = radian*(180/pi) print(degree) Sample Output: Input radians: 10 572.7272727272727..
    Pictorial Presentation:.
    Flowchart: ... .
    Python Code Editor: ... .
    Have another way to solve this solution?.

    Which function is used to convert an angle from radians into degrees?

    The Excel DEGREES function converts angles (expressed in radians) to degrees. For example, the formula =DEGREES(PI()) returns 180. angle - Angle in radians that you want to convert to degrees.

    What is radians function in Python?

    The math. radians() method converts a degree value into radians. Tip: See also math. degrees() to convert an angle from radians to degrees.

    Does Python calculate in radians or degrees?

    Python includes two functions in the math package; radians converts degrees to radians, and degrees converts radians to degrees. Note that all of the trig functions convert between an angle and the ratio of two sides of a triangle.