in this casethe global is changed the keyword global tells python that we do want to change global variableand not define new local one as general ruleone should minimize the use of global variables inside functions andinsteaddefine all the variables used inside function either as local variables or as arguments passed to the function to the function similarlyif we want the function to change global variable then we should make the function return this variableinstead of using the keyword global it is difficult to think of single example where using global is the best solutionand in practice it should never be used if we actually wanted the function above to change the global rthe following is better wayp def amount( , ) *( + / )** return ar amount( print( rnotice thatherewe return two values from the functionseparated by commajust as in the list of argumentsand we also assign the returned values to the global variables in the line where the function is called although this simple example might not be the most useful in practicethere are many cases in which it is useful for function call to change global variable in such cases the change should always be performed in this wayby passing the global variable in as an argumentreturning the variable from the functionand then assigning the returned value to the global variable following these steps is far better than using the global keyword inside the functionsince it ensures that each function is self-contained entitywith clearly defined interface to the rest of the code through the list of arguments and return values multiple return values are returned as tuple for more practically relevant example of multiple return valuessay we want to implement mathematical function so that both the function value and its derivative are returned considerfor instancethe simple physics formula that describes the height of an object in vertical motiony(tv ( / )gt where is the initial velocityg is the gravitational constantand is time the derivative of the function is (tv -gtand we can implement python function that returns both the function value and the derivativedef yfunc(tv ) * * * ** dydt * return ydydt