Open In App

Python | Decimal sqrt() method

Last Updated : 05 Sep, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

Decimal#sqrt() : sqrt() is a Decimal class method which returns the Square root of a non-negative number to context precision.

Syntax: Decimal.sqrt()

Parameter: Decimal values

Return: the Square root of a non-negative number to context precision.

Code #1 : Example for sqrt() method




# Python Program explaining 
# sqrt() method
  
# loading decimal library
from decimal import *
  
  
# Initializing a decimal value
a = Decimal(1)
  
b = Decimal(2)
  
# printing Decimal values
print ("Decimal value a : ", a)
print ("Decimal value b : ", b)
  
  
# Using Decimal.sqrt() method
print ("\n\nDecimal a with sqrt() method : ", a.sqrt())
  
print ("Decimal b with sqrt() method : ", b.sqrt())


Output :

Decimal value a :  1
Decimal value b :  2


Decimal a with sqrt() method :  1
Decimal b with sqrt() method :  1.414213562373095048801688724

Code #2 : Example for sqrt() method




# Python Program explaining 
# sqrt() method
  
# loading decimal library
from decimal import *
  
  
# Initializing a decimal value
a = Decimal(300)
  
b = Decimal(15)
  
  
# printing Decimal values
print ("Decimal value a : ", a)
print ("Decimal value b : ", b)
  
  
# Using Decimal.sqrt() method
print ("\n\nDecimal a with sqrt() method : ", a.sqrt())
  
print ("Decimal b with sqrt() method : ", b.sqrt())


Output :

Decimal value a :  300
Decimal value b :  15


Decimal a with sqrt() method :  17.32050807568877293527446342
Decimal b with sqrt() method :  3.872983346207416885179265400



Similar Reads

Python | sympy.sqrt() method
With the help of sympy.sqrt() method, we can find the square root of any number by using sympy.sqrt() method. Syntax : sympy.sqrt(number) Return : Return square root of any number. Example #1 : In this example we can see that by using sympy.sqrt() method, we can get the square root of any number. # import sympy import sympy # Use sympy.sqrt() metho
1 min read
Python | sympy.sqrt() method
With the help of sympy.sqrt() method, we can find the square root of any value in terms of values and also in terms of symbolically simplified mathematical expression. Syntax: sqrt(val) Parameters: val – It is the value on which square root operation is to be performed. Returns: Returns square root in terms of values and symbolically simplified mat
1 min read
Python | cmath.sqrt() method
With the help of cmath.sqrt() method, we can find the value of square root any number by passing it to cmath.sqrt() method. Syntax : cmath.sqrt(value) Return : Return the square root of any value. Example #1 : In this example we can see that by using cmath.sqrt() method, we are able to get the values of square root by passing value to it. # importi
1 min read
Python math.sqrt() function | Find Square Root in Python
sqrt() function returns square root of any number. It is an inbuilt function in Python programming language. In this article, we will learn more about the Python Program to Find the Square Root. sqrt() Function We can calculate square root in Python using the sqrt() function from the math module. In this example, we are calculating the square root
3 min read
numpy.sqrt() in Python
numpy.sqrt(array[, out]) function is used to determine the positive square-root of an array, element-wise. Syntax: numpy.sqrt() Parameters: array : [array_like] Input values whose square-roots have to be determined. out : [ndarray, optional] Alternate array object in which to put the result; if provided, it must have the same shape as arr. Returns
3 min read
Python | Decimal compare() method
Decimal#compare() : compare() is a Decimal class method which compares the two Decimal values. Syntax: Decimal.compare() Parameter: Decimal values Return: 1 - if a > b -1 - if a < b 0 - if a = b Code #1 : Example for compare() method # Python Program explaining # compare() method # loading decimal library from decimal import * # Initializing
2 min read
Python | Decimal is_subnormal() method
Decimal#is_subnormal() : is_subnormal() is a Decimal class method which checks whether the Decimal value is subnormal. Syntax: Decimal.is_subnormal() Parameter: Decimal values Return: true - if the Decimal value is subnormal otherwise false Code #1 : Example for is_subnormal() method # Python Program explaining # is_subnormal() method # loading dec
2 min read
Python | Decimal logb() method
Decimal#logb() : logb() is a Decimal class method which returns the adjusted exponent of the Decimal value. Syntax: Decimal.logb() Parameter: Decimal values Return: the adjusted exponent of the Decimal value. Code #1 : Example for logb() method # Python Program explaining # logb() method # loading decimal library from decimal import * # Initializin
2 min read
Python | Decimal conjugate() method
Decimal#conjugate() : conjugate() is a Decimal class method which returns the self, this method is only to comply with the Decimal Specification Syntax: Decimal.conjugate() Parameter: Decimal values Return: the self Decimal value Code #1 : Example for conjugate() method # Python Program explaining # conjugate() method # loading decimal library from
2 min read
Python | Decimal copy_sign() method
Decimal#copy_sign() : copy_sign() is a Decimal class method which returns the copy of the first Decimal value with the sign set to be the same as the sign of the second Decimal value. Syntax: Decimal.copy_sign() Parameter: Decimal values Return: the copy of the first Decimal value with the sign set to be the same as the sign of the second Decimal v
2 min read
Article Tags :
Practice Tags :