Sep-30-2019, 01:43 PM
But why do it that way? What's the advantage to using globals instead of parameters and return values? Take the last bit of code you posted. In it you have
If finit was instead:
d=finit(x)
. This changes the global variables a, b, and c. But there is no way to know that from looking at that line of code. That makes your code harder to follow, and therefore harder to maintain, and also easier for bugs to creep in. And why assign to d? finit has no return value, so d is always going to be None.If finit was instead:
def finit(): return 'ai', 'bi', 'ci'and you called it with
a, b, c = finit()
, it would be clear that a, b, and c are changed by the finit function. Then f1 could be defined as:def f1(a, b, c, x): print('f1: ', a, b, c, x)and when you call it, it becomes clear that f1 is making use of those variables.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures