UPDATE
In the original post, I showed a solution that uses lmfit , which allows you to assign borders to your parameters. Starting with version 0.17, scipy also allows you to directly bind borders to your parameters (see the documentation ). Below you will find this solution after EDIT , which we hope will serve as a minimal example of how to use scipy curve_fit with parameter boundaries.
Original post
As suggested by @Warren Weckesser, you can use lmfit to accomplish this task, which allows you to assign boundaries to your parameters and avoids this "ugly" if statement.
Since you are not providing any data, I created some of them that are shown here:

They follow the law f(x) = 10.5 * x ** (-0.08)
I adapt them, as suggested by @ roadrunner66, by converting a power law to a linear function:
y = N * x ** a ln(y) = ln(N * x ** a) ln(y) = a * ln(x) + ln(N)
So, I first use np.log as np.log , and then do the fit. When I use lmfit now, I get the following output:
[[Variables]] lN: 2.35450302 +/- 0.019531 (0.83%) (init= 1.704748) a: -0.08035342 +/- 0.005158 (6.42%) (init=-0.5)
So a pretty close to the original value, and np.exp(2.35450302) gives 10.53, which is also very close to the original value.
Then the graph looks like this: since you can see that the fit describes the data very well:

Here is all the code with a few inline comments:
import numpy as np import matplotlib.pyplot as plt from lmfit import minimize, Parameters, Parameter, report_fit
EDIT
Assuming you have scipy 0.17 installed, you can also do the following: curve_fit . I show it for your initial definition of a power law (the red line in the graph below), as well as for the logarithmic data (black line in the graph below). Data is generated as described above. The plot is as follows:

As you can see, the data are described very well. If you print popt and popt_log , you get respectively array([ 10.47463426, 0.07914812]) and array([ 2.35158653, -0.08045776]) (note: for letter 1 you have to take the exponent of the first argument - np.exp(popt_log[0]) = 10.502 , which is close to the original data).
Here is the whole code:
import numpy as np import matplotlib.pyplot as plt from scipy.optimize import curve_fit