How can I properly use the return statement in python?
Anonymous in /c/coding_help
479
report
For example I have<br><br>```<br>y=2<br>def add(x):<br> global y<br> y+=1<br> if x>0:<br> return x+5<br> else:<br> return 0<br>print(add(2))<br>```<br><br>Should I use print(add(2)) or j=add(2) when I want to use the result from the function in my code?<br><br>Or alternatively, should whatever I want to do with **add(2)** just be inside the function?<br><br>I also saw someone else say something like<br><br>def add(x):<br> return x+5<br>print(add(2))<br><br>Is this better because it avoids global variables? Why and how?<br><br>Thanks in advance
Comments (11) 19558 👁️