Cara menggunakan degree to rad python

math.degrees(x)

Fungsi ini digunakan untuk mengonversi sudut dalam radian ke dalam bentuk derajat.

>>> math.degrees(1.5707963267948966)
90.0
>>> math.degrees(0.7853981633974483)
45.0
>>>

Variabel math.e

Variabel math.e berisi nilai yang menyatakan konstanta e, yaitu: 2.718(…).

>>> math.e
2.719281828459045
>>>

Fungsi math.exp()

math.exp(x)

Fungsi ini digunakan untuk mencari nilai eksponensial x, (ex), dengan nilai e diambil dari math.e.

>>> math.exp(3)
20.085536923187668
>>>
>>> math.e ** 3
20.085536923187664
>>>

Fungsi math.fabs()

math.fabs(x)

Fungsi ini digunakan untuk mencari nilai absolut, mirip dengan fungsi abs(). Perbedaannya, fabs() tidak bisa diterapkan untuk bilangan kompleks, sedangkan abs() bisa.

>>> math.fabs(-4)  # int
4.0
>>>
>>> math.fabs(-9.0)  # float
9.0
>>>
>>>math.fabs(-3+4j)  # complex
Traceback (most recent call last):
   File "<pyshell#64>", line 1, in 
      math.fabs(-3+4j)   # complex
TypeError: can't convert complex to float
>>>
>>> abs(-3+4j)
5.0
>>>

Fungsi math.factorial()

math.factorial(x)

Fungsi ini digunakan untuk mencari nilai faktorial x.

>>> math.factorial(3)
6
>>> math.factorial(5)
120
>>> math.factorial(9)
362880
>>>
>>> faktorial = 1
>>> for i in range(1, 10):
   faktorial *= i
>>> faktorial
362880
>>>
Sumber: Modul Belajar Singkat Pemrograman Python 3 by Budi Raharjo

Telah Terbit 22 Oktober 2018

In this python tutorial, you will learn about the Python degrees to radians. Let us see how to convert degrees to radians in Python.

Also, we will check:

  • What is a python math module?
  • Python degrees to radians
  • Python radians to degrees
  • Python degrees to radians using numpy
  • Python radians to degrees using numpy
  • Write a python program to convert radian to degree
  • How to print the degree symbol in python
  • How to convert a number to radians in python
  • Convert angles from degrees to radians in python

What is a python math module?

Python has a built-in module that can be used for the mathematical task on numbers. The math module contains functions for calculating the various trigonometric ratios for a given angle.

The math module presents two angles conversion function which is degrees() and radians(). The math module has a set of methods.

  • Python File methods (With Useful Examples)

In python, math.radians() method is used to convert a degree value to radians. So, we will first import math module.

Example:

import math
print(math.radians(120))

After writing the above code (python degrees to radians), Ones you will print “math.radians(120)” then the output will appear as a “ 2.0943951023931953 “.

Here, math.radians() convert the degree to radians value.

You can refer to the below screenshot for python degrees to radians.

Cara menggunakan degree to rad python
Python degrees to radians

This is how we can convert degrees to radian in Python.

Read How to Convert Python DataFrame to JSON

Python radians to degrees

Here, we will see how we can convert radians to degrees in python.

To convert radians to degrees, we will use math.degrees() for convert radians to degrees.

Example:

import math
radians = 1.5707963267948966
radians = math.degrees(radians)
print(radians)

After writing the above code (python radians to degrees), Ones you will print “math.degrees()” then the output will appear as a “ 90.0 “. Here, math.degrees(radians) convert the radians value to degrees.

You can refer to the below screenshot for python radians to degrees.

Cara menggunakan degree to rad python
Python radians to degrees

The above code, we can use to convert radians to degrees in Python.

Python degrees to radians using numpy

Let’s see how to convert degrees to radians using numpy.

To convert degrees to radians, we have to import numpy package first. It has an inbuilt function name deg2rad() which can directly convert degrees to radians.

Example:

import numpy as np
print("degrees to radian: ",np.deg2rad(2))

After writing the above code (python degrees to radians using numpy), Ones you will print ” np.deg2rad(2)” then the output will appear as “ degrees to radian: 0.03490658503988659 “. Here, np.deg2rad(2) will convert degrees to radians.

You can refer to the below screenshot for Python degrees to radians using numpy.

Cara menggunakan degree to rad python
Python degrees to radians using numpy

Python radians to degrees using numpy

To convert radians to degrees in Python, we have to import numpy package first. It has an inbuilt function name rad2deg() which can directly convert radians to degrees.

Example:

import numpy as np
print("radian to degree : ",np.rad2deg(2))

After writing the above code (python radians to degrees using numpy), Ones you will print ” np.rad2deg(2)” then the output will appear as “ radian to a degree: 114.59155902616465 “. Here, np.rad2deg(2) will convert radians to degrees.

You can refer to the below screenshot for python radians to degrees using numpy.

Cara menggunakan degree to rad python
Python radians to degrees using numpy

Write a python program to convert radian to degree

In this program, we have taken the pi value as 3.14159 and the radian as 10 while printing it will convert the radian to a degree.

def convert(radian):
    pi = 3.14159
    degree = radian * (180/pi)
    return degree
radian = 10
print("degree =",(convert(radian)))

After writing the above code (write a python program to convert radian to a degree), Ones you will print “convert(radian)” then the output will appear as a “degree = 572.9582790879778“. Here, degree = radian * (180/pi) and radian=10. So in this way, we can convert radian to a degree.

You can refer to the below screenshot for python program to convert radian to degree.

Cara menggunakan degree to rad python
Write a python program to convert radian to degree

How to print the degree symbol in python

For printing the degree symbol in python, we will use u”\N{Degree Sign}” and we have used unicode to print the degree symbol.

Example:

degree_sign = u"\N{Degree Sign}"
print(degree_sign)

After writing the above code (how to print the degree symbol in python), Once you will print “(degree_sign)” then the output will appear as a “ ° “. Here, u”\N{Degree Sign}” is used to print the degree symbol.

You can refer to the below screenshot how to print the degree symbol in python.

Cara menggunakan degree to rad python
How to print the degree symbol in python

How to convert a number to radians in python

Firstly, we need to import math module. To convert a number to radians in Python, we will use radians(number) to convert the number to radians and we need to call this function using a math object.

Example:

import math
print("radians(5) :", math.radians(5))

After writing the above code (how to convert a number to radians in python), Once you will print “math.radians(5)” then the output will appear as a “ radians(5): 0.08726646259971647 “. Here, math.radians(5) is used to convert a number to radians in python.

You can refer to the below screenshot how to convert a number to radians in python.

Cara menggunakan degree to rad python
How to convert a number to radians in python

Convert angles from degrees to radians in python

Now, we will see how to convert angles from degrees to radians in python.

We will first import numpy module and then we will print np.radians(120) and it will get converted to radians.

Example:

import numpy as np
print (np.radians(120))

You can refer to the below screenshot Convert angles from degrees to radians in python.

Cara menggunakan degree to rad python
Convert angles from degrees to radians in python

You may like the following Python tutorials:

  • Linked Lists in Python
  • How to display calendar in Python
  • How to make a calculator in Python
  • Python print 2 decimal places
  • Python generate random number and string
  • Python write list to file with examples
  • Command errored out with exit status 1 python
  • Python write String to a file
  • Priority queue in Python
  • Escape sequence in Python

In this Python tutorial we learned about Python degrees to radians. Also, we covered these below topics:

  • What is a python math module?
  • How to convert degrees to radians in Python
  • How to convert radians to degrees in Python
  • Python degrees to radians using numpy
  • Python radians to degrees using numpy
  • Write a python program to convert radian to degree
  • How to print the degree symbol in python
  • How to convert a number to radians in python
  • Convert angles from degrees to radians in python

Cara menggunakan degree to rad python

Python is one of the most popular languages in the United States of America. I have been working with Python for a long time and I have expertise in working with various libraries on Tkinter, Pandas, NumPy, Turtle, Django, Matplotlib, Tensorflow, Scipy, Scikit-Learn, etc… I have experience in working with various clients in countries like United States, Canada, United Kingdom, Australia, New Zealand, etc. Check out my profile.