AppDividend
Latest Code Tutorials

# Python erf: How to Use Math.erf() in Python Example

Python math.erf() method will return the error at x. The error function is also known as the gauss error function, and the function throws an error if any non-number is passed as a parameter.

## Python erf()

Python erf() is an inbuilt method that is defined under the math module, which is used to find the error function at x if x is the parameter passed. For example if x is passed as a parameter in erf function (erf(x)) it returns error function. We can use a math module by importing it.

### Syntax

```math.erf(var)
```

Here var is the variable of which error function we have to find.

### Parameters

It takes one argument var, which takes values of numeric datatype and throws TypeError if an argument is of any other data type is passed.

### Return Value

It returns the error function value of the number in the float datatype.

See the following sample code.

```import math

var = 0.6
print(math.erf(var))
```

### Example programs on erf() method in Python

#### Example 1: Write a program to show the working of the erf() method in Python.

```import math
a1 = 0.3
b1 = 0.9
c1 = 0.7
d1 = 0.2

print("Value for parameter ", a1, " is ", math.erf(a1))
print("Value for parameter ", b1, " is ", math.erf(b1))
print("Value for parameter ", c1, " is ", math.erf(c1))
print("Value for parameter ", d1, " is ", math.erf(d1))
```

#### Output

```Value for parameter  0.3  is  0.3286267594591274
Value for parameter  0.9  is  0.796908212422832
Value for parameter  0.7  is  0.6778011938374183
Value for parameter  0.2  is  0.22270258921047847
```

In this code example, we have seen that by passing a vaild parameter, which is different for different examples, we get the desired erf() method solution, which is the error function value.

#### Example 2: Write a program to pass the value out of range from the erf() function and display the output.

See the following code.

```import math

x = 'b'
print(math.erf(x))
```

#### Output

```TypeError: must be real number, not str
```

In this example, we’ve seen that by passing a parameter which is not of number type, the function throws an error.