python - Globals as function input instead arguments -


i'm learning how python works , after reading while i'm still confused globals , proper function arguments. consider case globals not modified inside functions, referenced.

can globals used instead function arguments? i've heard using globals considered bad practice. in case?

calling function without arguments:

def myfunc() :     print myvalue  myvalue = 1 myfunc() 

calling function arguments

def myfunc(arg) :     print arg  myvalue = 1 myfunc(myvalue) 

i've heard using globals considered bad practice. in case?

it depends on you're trying achieve. if myfunc() supposed print value, then...

def myfunc(arg):     print arg  myfunc(1) 

...is better, if myfunc() should print same value, then...

myvalue = 1  def myfunc():     print myvalue  myfunc() 

...is better, although example simple, may factor out global, , use...

def myfunc():     print 1  myfunc() 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -