Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
use of global
#14
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 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
Reply


Messages In This Thread
use of global - by wpo - Sep-30-2019, 08:53 AM
RE: use of global - by buran - Sep-30-2019, 09:00 AM
RE: use of global - by wpo - Sep-30-2019, 09:13 AM
RE: use of global - by newbieAuggie2019 - Sep-30-2019, 10:28 AM
RE: use of global - by newbieAuggie2019 - Sep-30-2019, 10:34 AM
RE: use of global - by buran - Sep-30-2019, 10:33 AM
RE: use of global - by newbieAuggie2019 - Sep-30-2019, 12:48 PM
RE: use of global - by wpo - Sep-30-2019, 10:38 AM
RE: use of global - by newbieAuggie2019 - Sep-30-2019, 10:55 AM
RE: use of global - by buran - Sep-30-2019, 10:43 AM
RE: use of global - by wpo - Sep-30-2019, 11:56 AM
RE: use of global - by buran - Sep-30-2019, 12:47 PM
RE: use of global - by wpo - Sep-30-2019, 01:27 PM
RE: use of global - by newbieAuggie2019 - Sep-30-2019, 02:14 PM
RE: use of global - by ichabod801 - Sep-30-2019, 01:43 PM
RE: use of global - by wpo - Sep-30-2019, 03:06 PM
RE: use of global - by buran - Sep-30-2019, 03:21 PM
RE: use of global - by ichabod801 - Sep-30-2019, 03:30 PM
RE: use of global - by stullis - Sep-30-2019, 07:45 PM
RE: use of global - by micseydel - Oct-02-2019, 10:06 PM
RE: use of global - by steve_shambles - Oct-17-2019, 04:21 AM
RE: use of global - by buran - Oct-17-2019, 06:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Global variable does not seem to be global. Columbo 6 5,328 Jul-15-2019, 11:00 PM
Last Post: Columbo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020