Hey so i was wondering which is the more efficient way, or better practice to do in this situation.
1,
def function():
global number
number += 2
Or 2,
def function(number):
return number += 2
Thanks.
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.
Sign up to join this communityHey so i was wondering which is the more efficient way, or better practice to do in this situation.
1,
def function():
global number
number += 2
Or 2,
def function(number):
return number += 2
Thanks.
Performance is irrelevant. Globals are evil (as gnat mentioned); you are best off forgetting the global
keyword exists. There is always a better way.