Search code examples
pythonreturn

Call argument from multi returned arguments function using Python


By using Python : I want to call just one argument from defined function (Angles) which return two arguments theta and phi. How can I call just theta value from Angles funcition and assign it to x value?

values = [1,-1]    
g = np.random.choice(values)
q= np.random.choice(values)   
def Angles ():
    theta = (((1 + g*g - ((1 - g*g)/(1 - g + 2*g*q))**2)/(2*g)))
    phi = 2 * math.radians(180) * q
    return theta,phi

x = cos(theta)

Solution

  • You have to call Angles first; theta will be the first element of the tuple returned by Angles.

    th, ph = Angles()
    x = cos(th)
    

    or

    x = cos(Angles()[0])