Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Python) Should I use parameters or make it global? [closed]

I have many functions that all share the same parameter. They will be inputting and outputting this parameter many times.

For example:

a = foo
a = fun(a)
a = bar(a)

def fun(a):
     ...
     return a

def bar(a):
     ...
     return a

What is more pro-grammatically correct, passing parameters through a function, or having it be globally accessible for all the functions to work with?

a = foo
fun()
bar()

def fun():
    global a
    ...

def bar():
    global a
    ...
like image 560
tisaconundrum Avatar asked Oct 22 '25 03:10

tisaconundrum


1 Answers

For re-usability of method, passing parameter is better way.

like image 123
Dharmesh Fumakiya Avatar answered Oct 24 '25 17:10

Dharmesh Fumakiya