Setting default arguments from arguments in python

I am trying to set the default value for an argument in a function that I defined. I also want the other argument to have a default value depending on the other argument. In my example, I am trying to build a quantum-mechanical wave function for hydrogen, but you do not need to know physics to help me.

def plot_psi(n,l,start=(0.001*bohr),stop=(20*bohr),step=(0.005*bohr)): 

where n is the main quantum number, l is the angular momentum, and start,stop,step is the array that I am calculating. But I need the default stop value to really depend on n , since n will affect the size of the wave function.

 def plot_psi(n,l,start=(0.001*bohr),stop=((30*n-10)*bohr),step=(0.005*bohr)): 

will be what I do, but n is not defined yet because the line is not complete. Any solutions? Or ideas for another way to arrange this? Thanks

+5
source share
1 answer

Use None as the default value and calculate the values ​​inside the function, e.g.

 def plot_psi(n, l, start=(0.001*bohr),stop=None,step=(0.005*bohr)): if stop is None: stop = ((30*n-10)*bohr) 
+3
source

Source: https://habr.com/ru/post/1209607/


All Articles