Related Articles

# Python | Decimal sqrt() method

• Last Updated : 05 Sep, 2019

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

```

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up